Hibernate学习笔记五

组件映射:

1)

Address.java:

   private StringhomeAddress;

   private StringschoolAddress;

为其生成setget方法

Student.java:

   private Stringid;

   private Stringname;

   private Addressaddress;

为其生成setget方法

Student.hbm.xml:

<classname="com.songjinghao.hibernate.Student"table="student">

      <idname="id"column="id"type="string">

        <generatorclass="uuid"></generator>

      </id>

      <propertyname="name"column="name"type="string"></property>

      <componentname="address"class="com.songjinghao.hibernate.Address">

        <propertyname="homeAddress"type="string"></property>

        <propertyname="schoolAddress"type="string"></property>

      </component>

</class>

2)

Contact.java:

   private Stringstudent_id;

   private Stringmethod;

   private Stringaddress;

为其生成setget方法

Student.java:

   private Stringid;

   private Stringname

   privateSet contacts =new HashSet();

为其生成setget方法

Student.hbm.xml:

<classname="com.songjinghao.hibernate.Student"table="student">

      <idname="id"column="id"type="string">

        <generatorclass="uuid"></generator>

      </id>

      <propertyname="name"column="name"type="string"></property>

      <setname="contacts"table="contact">

        <keycolumn="student_id"></key>

        <composite-elementclass="com.songjinghao.hibernate.Contact">

           <propertyname="method"type="string"></property>

           <propertyname="address"type="string"></property>

        </composite-element>

      </set>

</class>


你可能感兴趣的:(Hibernate学习笔记五)