浅析Hibernate映射(五)——集合映射

集合映射主要包括:set、list、array、map的映射

对象模型:

映射后的关系模型:

映射文件:

  1. <hibernate-mapping>  
  2.     <class name="com.jialin.hibernate.CollectionMapping" table="t_collection_mapping">  
  3.         <id name="id">  
  4.             <generator class="native"/>  
  5.         </id>  
  6.         <property name="name"/>  
  7.         <set name="setValues" table="t_set_values">  
  8.             <key column="set_id"/>  
  9.             <element type="string" column="set_value" not-null="true"/>  
  10.         </set>  
  11.         <list name="listValues" table="t_list_values">  
  12.             <key column="list_id"/>  
  13.             <list-index column="list_index"/>  
  14.             <element type="string" column="list_value"/>  
  15.         </list>  
  16.         <array name="arrayValues" table="t_array_values">  
  17.              <key column="array_id"/>  
  18.              <list-index column="array_index"/>  
  19.              <element type="string" column="array_value"/>  
  20.         </array>  
  21.         <map name="mapValues" table="t_map_values">  
  22.             <key column="map_id"/>  
  23.             <map-key type="string" column="map_key"/>  
  24.             <element type="string" column="map_value"/>  
  25.         </map>  
  26.     </class>  
  27. </hibernate-mapping>  
原文地址:https://www.cnblogs.com/niuchunjian/p/4520236.html