Hibernate_集合类映射配置

  一、集合映射的元素大致有如下几种:

  • List: 用于映射 List 集合属性
  • Set: 用于映射 Set 集合属性
  • Map: 用于映射 Map 集合性
======以下三种使用率较低======
  • Array: 用于映射数组集合属性
  • Bag: 用于映射无序集合
  • idbag: 用于映射无序集合,但为集合增加逻辑次序
注意:要使用接口类来定义集合类

1)这是List的.hbm.xml配置文件,private List school = new ArrayList();
<hibernate-mapping >     
 <class name="cn.janwer.News" table="news">     
   <id name="id" column="pid">     
    <generator class="identity"/>     
   </id>     
        
    <property name="title" length="50" column="TITLE"/>     
    <property name="content" length="50" column="CONTENT"/>     
    <list name="schools" table="school">  
      <key column="pid" not-null="true"/>  
      <list-index column="list_order" />  
      <element type="string" column="school_name"/>     
    </list>     
      
</class>     
</hibernate-mapping>  

2)Set集合类:无序、 不可重复的集合
<pre name="code" class="html" style="font-size: 14px; line-height: 19px;"><hibernate-mapping >     
 <class name="cn.janwer.News" table="news">     
   <id name="id" column="pid">     
    <generator class="identity"/>     
   </id> 
 
 
<set name="schools" table="school">  
   <key column="pid" not-null="true"/>     
   <element type="string" column="school_name" not-null="true"/>     
</set> 
<pre name="code" class="html" style="font-size: 14px; line-height: 19px;"></class>     
</hibernate-mapping>  

 
 
3)Map集合类: Map 集合属性使用 map 元素映射时,该 map 元素需要 key 和 map-key 两个子元素。其中 key 子元素用于映射外键列,而 map-key 子元素则用于映射 Map 集合的 Key 
<hibernate-mapping >     
 <class name="cn.janwer.News" table="news">     
   <id name="id" column="pid">     
    <generator class="identity"/>     
   </id> 
<map name="school" table="schools">  
      <key column="pid" not-null="true" />       
      <map-key type="string" column="indet"/>     
      <element type="float" column="score"/>     
 </map>  
<pre name="code" class="html" style="font-size: 14px; line-height: 19px;"></class>     
</hibernate-mapping>  

 
 
性能的话:一般是List最高,Array最低


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值