Person 类中有 Name 组件 Name 代码如下:
package zhourj.hibernate.list;
public class Name {
private String first;
private String last;
//引用 拥有 Name 的 Person
private Person owner;
public Name(){
}
public String getFirst() {
return first;
}
public void setFirst(String first) {
this.first = first;
}
public String getLast() {
return last;
}
public void setLast(String last) {
this.last = last;
}
public Person getOwner() {
return owner;
}
public void setOwner(Person owner) {
this.owner = owner;
}
}
在 Person.hbm.xml 文件中添加如下代码::
<component name="myname" class="Name" unique="true">
<!-- 指定 owner 属性代表的实体 -->
<parent name="owner"/>
<property name="first"></property>
<property name="last"></property>
</component>
运行结果:
可以看到表的结构中 多了 两列 first last 这个是分表 来自 Name 中的两个属性