Hibernate学习笔记(五)【映射组成关系】

标配BASE

<hibernate-mapping >
  <class name="mypack.People" table="PEOPLE" >
    <id name="id" type="long" column="ID">
      <generator class="increment"/>
    </id>
    <property name="name" type="string" column="NAME" />
  </class>
</hibernate-mapping>

 

映射组成关系

 

<hibernate-mapping >
  <class name="mypack.People" table="PEOPLE" >
    <id name="id" type="long" column="ID">
      <generator class="increment"/>
    </id>
    <property name="name" type="string" column="NAME" />
    <component name="hand" class="mypack.HAND">
           <parent name="people" />
           <property name="color" type="string" column="COLOR"/>
    </component>  
  </class>
</hibernate-mapping>

说明:

1.People和Hand是组合关系,在People类中有个成员是Hand类,名字是hand

2.标签<component>和<property>没多大区别 ,对应一个成员

3.标签<component>和<class>其实也没多大区别,<component>里面可以嵌套<class>能嵌套的东西
比如嵌套他自己<component>或者<set>什么的

3.标签<component>一点点区别是他里面有个<parent>这你懂的

4.用法就是Hand完全由parent--》People控制,Hand属于Value而不是Entity实体,无OID

你可能感兴趣的:(java,Hibernate,企业应用,映射组成关系)