一、集合映射的元素大致有如下几种:
- 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>
<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>
<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最低