hibernate关系映射总结2

来源:互联网 发布:汉客拉杆箱怎么样知乎 编辑:程序博客网 时间:2024/06/05 14:09

多对一,一对多

<set name="idCards" inverse="true" cascade="all">
            <key column="idCardsid"/>  
            <one-to-many class="domain.IdCard"/>  
        </set> 

集合映射

         <!—set元素用来映射java.util.Set类型的属性

                     Name属性:指定要映射的属性名

                     Table属性:指定对应的数据库表名

n       > 

n         <set name=”hobbies” table=”student_hobby:>

u       <!--  key 子元素:指定集合属性对应的表的外键列 -- >

u       <key column=”student_id:/>

u       <! – element 子元素:映射集合内的元素 -->

u       <element type=”string” column=”hobby_name” not-null=”true”/>

</set>

<!  -- 

              List元素用来映射java.util.List类型的属性

              Name属性:指定要映射的属性名

              Table属性:指定对应的数据库表名

n       > 

<list name=”hobbies” table=”student_hobby”>

       <! --  key 元素:指定集合属性对应的表的外键列 -- >

       <key column=”student_id”/>

       <!—list-index 元素:指定索引列 -- >

       <list-index column=”position”/>

       <!—element 元素:映射集合内的元素 -- >

       <element type=”string” column=”hobby_name” not-null=”ture”>

</list>

<!--  

Bag元素用来映射java.util.Collection或java.util.List类型的属性

       Name属性:指定要映射的属性名

       Table属性:指定对应的数据库表名

n       > 

<bag name=”hobbies” table=”student_hobby”>

       <! -- key 元素:指定集合属性对应的表的外键列 -- >

       <key column=”student_id”/>

       <!—element 元素:映射集合内的元素 --  >

       <element type=”string” column=”hobby_name” not-null=”true”/>

</bag>

<map name=”hobbies” table=”student_hobby”>

       <!--  key 元素:指定集合属性对应的表的外键列 --  >

       <key column=”student_id”/>

       <!-- map-key 元素:指定map属性的键在对应表中的列 --  >

       <map-key column=”hobby_id” type=”long”/>

       <!--  element元素:映射集合内的元素-- >

       <element type=”string” column=”hobby_name” not-null=”true”/>

</map>

排序sort=”natural”可选值:unsorted(不排序)、natural(按compareTo()方法进行比较厚排序)、

order_by=”hobby-name desc”排序


0 0