`

Hibernate的集合映射

阅读更多
l       Hibernate中将集合分为四类:

1、bag类:元素无序,可重复

2、set类:元素无序,不可重复

3、list类:元素有序,可重复

4、array类:数组

5、map类:映射关系

l       除bag类集合外,其它集合均可在Java API中找到对应接口。

Bag一般使用list来映射

<bag name="unitNames" table="unit" lazy="false" order-by="unit_id desc">

       <key column="building_id"/>

       <element column="unit_name" type="string"/>

    </bag

l       Set集合在使用上与bag大至相同:

<set name="names" table="person_names">

       <key column="person_id"/>

       <element column="person_name"                             type="string"/>

</set>

<list name="unitNames" table="unit" lazy="false" >

       <key column="building_id"/>

       <index column="unit_id" />

       <element column="unit_name" type="string"/>

</list>



<list name="carComponents“ table="CarComponents">

       <key column="carId"/>

       <list-index column="sortOrder"/>

       <composite-element class="CarComponent">

              <property name="price"/>

              <property name="type"/>

              <property name="serialNumber" column="serialNum"/>

       </composite-element>

</list>

<map name="unit" table="unit">

<key column="building_id"></key>

<map-key column="id" type="int" />

<element type="string" column="unit"></element>

</map>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics