原理:每个集合一个表
原理图如下:
集合的id是来自于那个总的值
对象模型如下:
public class CollectionMapping {
private int id;
private String name;
private Set setValues = new HashSet();
private List listValues = new ArrayList();
private String[] arrayValues;
private Map mapValues;
}
具体映射
<hibernate-mapping>
<class name="com.bjpowernode.hibernate.CollectionMapping" table="t_collection_mapping">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
<set name="setValues" table="t_set_values">
<key column="set_id"/>
<element type="string" column="set_value" not-null="true"/>
<!--
<composite-element class=""></composite-element>
-->
</set>
<list name="listValues" table="t_list_values">
<key column="list_id"/>
<list-index column="list_index"/>
<element type="string" column="list_value"/>
</list>
<array name="arrayValues" table="t_array_values">
<key column="array_id"/>
<list-index column="array_index"/>
<element type="string" column="array_value"/>
</array>
<map name="mapValues" table="t_map_values">
<key column="map_id"/>
<map-key type="string" column="map_key"/>
<element type="string" column="map_value"/>
</map>
</class>
</hibernate-mapping>