具体表继承
时间:2011-02-19 来源:魔战
Animal类:
package com.jzq.hibernate;
public class Animal {
private int id;
private String name;
private String sex;
public Animal(){}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
Bird类:
package com.jzq.hibernate;
public class Bird extends Animal {
private int height;
public Bird(){}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
}
Pig类:
package com.jzq.hibernate;
public class Pig extends Animal {
private int height;
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public Pig(){}
}
配置文件:
<hibernate-mapping>
<class name="Animal" package="com.jzq.hibernate">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
<property name="sex"/>
<!-- 连接子类 Pig -->
<joined-subclass name="Pig" table="t_pig">
<key column="pid"/>
<property name="weight"/>
</joined-subclass>
<!-- 连接子类 Bird -->
<joined-subclass name="Bird" table="t_bird">
<key column="bid"/>
<property name="height"/>
</joined-subclass>
</class>
</hibernate-mapping>