hibernate关系映射总结2

多对一,一对多

<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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值