Hibernate学习笔记7

来源:互联网 发布:安卓流畅优化软件 编辑:程序博客网 时间:2024/06/15 11:05
 

Hibernate学习笔记7

学习课程:

Component映射——组建映射

Hibernate_15_Compontent_Mapping

Composite映射——复合主键映射

Hibernate_16_Composite_Mapping

Collection映射——集合映射

Hibernate_17_Collection_Mapping

学习内容:

Component映射——组建映射

对象模型:

Component映射——组件映射

称为值,对象实体的逻辑组成部分,它与实体的根本区别是没有OID

优点:实现了对象模型的细粒度划分,层次会更分明,复用率更高

Contact: (String)email , (String)address , (String)zipCode , (String)contactTel

User:(int)id , (String)name , (Contact)contact

Employee: (int)id , (String)name , (Contact)contact

映射文件:

  1. <class name="User" table="t_user" lazy="true">
  2. …………
  3. …………
  4. <component name="contact" >
  5. <property name="email" />
  6. <property name="address" />
  7. <property name="zipCode" />
  8. <property name="contactTel" />
  9. </component>
  10. </class>

Composite映射——复合主键映射

对象模型:

Component映射——组件映射

称为值,对象实体的逻辑组成部分,它与实体的根本区别是没有OID

优点:实现了对象模型的细粒度划分,层次会更分明,复用率更高

Contact: (String)email , (String)address , (String)zipCode , (String)contactTel

User:(int)id , (String)name , (Contact)contact

Employee: (int)id , (String)name , (Contact)contact

映射文件:

  1. <class name="Child" table="t_child" lazy="true">
  2. <composite-id name="father">
  3. <key-property name="year" />
  4. <key-property name="month" />
  5. <key-property name="day" />
  6. </composite-id>
  7. <property name="name" />
  8. </class>

Collection映射——集合映射

映射:

Set setValue

List listValue

array String[] arrayValue

Map mapValue

建立五张表

第一张表t_collection

id

name

第二张表 t_set_value

字段信息:

set_id(外键关联于id) 

set_value

映射文件:

  1. <set name="setValue" table="t_set_value">
  2. <key column="set_id"/>
  3. <element type="string" column="set_value"/>
  4. </set>

第三张表 t_list_value,list保存时需要保存索引顺序,不可以打乱

字段信息:

list_id(外键关联于id)

list_value

list_index

映射文件

  1. <list name="listValue" table="t_list_value">
  2. <key column="list_id"/>
  3. <list-index column="list_index"/>
  4. <element type="string" column="list_value"/>
  5. </list>

第四张表 t_array_value,注需索引

字段信息:

array_id

array_value

array_index

映射文件:

  1. <array name="arrayValue" table="t_array_value">
  2. <key column="array_id" />
  3. <list-index column="array_index"/>
  4. <element type="string" column="array_value"/>
  5. </array>

第五张表:t_map_value key和value

字段信息:

map_id

map_key 

map_value

映射文件:

  1. <map name="mapValue" table="t_map_value">
  2. <key column="map_id"/>
  3. <map-key type="string" column="map_key"/>
  4. <element type="string" column="map_value"/>
  5. </map>

原创粉丝点击