hibernate常用映射配置总结
2017-02-17 00:03
141 查看
集合映射
<set name="" table="">
<key column=""></key>
<element column="" type=""></element>
</set>
<list name="" table="">
<key column=""></key>
<index column=""></index>
<element column="" type=""></element>
</list>
<map name="" table="">
<key column=""></key>
<map-key column="" type=""></map-key>
<element column="" type=""></element>
</map>
复合主键映射
tips:复合主键一定要实现Serializable接口
<composite-id name="" class="复合主键所属类类">
<key-property name="" column=""></key-property>
</composite-id>
一对多
<set name="" >
<key column=""></key>
<one-to-many class=""/>
</set>
多对一
<many-to-one name="" column="" class=""></many-to-one>
多对多(中间表实现)
<set name="集合属性的名字" table="中间表的名字">
<key column="中间表引用的字段名(外键,对应当前配置表的主键)"></key>
<many-to-many column="中间表外键对应的字段" class="集合属性的类型s"></many-to-many>
</set>
一对一
(1)通过外键映射
无外建方
<one-to-one name="" class="" property-ref=""></one-to-one>
有外键方
<many-to-one name="" column="" class="" unique="true 多对一并且外键为唯一值实现一对一" ></many-to-one>
(2)通过主键映射
无主键方
<one-to-one name="" class=""></one-to-one>
有主键方
<id name="">
<generator class="foreign">
<param name="property">和下面的name要一样</param>
</generator>
</id>
<one-to-one name="" class="" constrained="true 添加外键约束"></one-to-one>
组合映射(类中包含类,映射到同一张表)
<component name="" class="">
<property name="" type=""></property>
</component>
继承映射
(1)简单的继承映射
每个子类都要有配置文件,然后通过<property></property>设定所有字段
(2)复杂的继承映射
(2.1)映射为一张表
<!-- 鉴别器 -->
<discriminator column="" type=""></discriminator>
<subclass name="" class="" discriminator-value="">
<property name="" type=""></property>
</subclass>
(2.2)父类,子类都映射一张表
<joined-subclass name="" table="">
<key column=""/>
<property name="" type=""></property>
<joined-subclass>
(2.2)每个子类都映射一张表
<id name="">
<generator class="不能为自增长主键生成器"></generator>
</id>
<union-subclass name="" table="">
<property name="" type=""></property>
</union-subclass>
<set name="" table="">
<key column=""></key>
<element column="" type=""></element>
</set>
<list name="" table="">
<key column=""></key>
<index column=""></index>
<element column="" type=""></element>
</list>
<map name="" table="">
<key column=""></key>
<map-key column="" type=""></map-key>
<element column="" type=""></element>
</map>
复合主键映射
tips:复合主键一定要实现Serializable接口
<composite-id name="" class="复合主键所属类类">
<key-property name="" column=""></key-property>
</composite-id>
一对多
<set name="" >
<key column=""></key>
<one-to-many class=""/>
</set>
多对一
<many-to-one name="" column="" class=""></many-to-one>
多对多(中间表实现)
<set name="集合属性的名字" table="中间表的名字">
<key column="中间表引用的字段名(外键,对应当前配置表的主键)"></key>
<many-to-many column="中间表外键对应的字段" class="集合属性的类型s"></many-to-many>
</set>
一对一
(1)通过外键映射
无外建方
<one-to-one name="" class="" property-ref=""></one-to-one>
有外键方
<many-to-one name="" column="" class="" unique="true 多对一并且外键为唯一值实现一对一" ></many-to-one>
(2)通过主键映射
无主键方
<one-to-one name="" class=""></one-to-one>
有主键方
<id name="">
<generator class="foreign">
<param name="property">和下面的name要一样</param>
</generator>
</id>
<one-to-one name="" class="" constrained="true 添加外键约束"></one-to-one>
组合映射(类中包含类,映射到同一张表)
<component name="" class="">
<property name="" type=""></property>
</component>
继承映射
(1)简单的继承映射
每个子类都要有配置文件,然后通过<property></property>设定所有字段
(2)复杂的继承映射
(2.1)映射为一张表
<!-- 鉴别器 -->
<discriminator column="" type=""></discriminator>
<subclass name="" class="" discriminator-value="">
<property name="" type=""></property>
</subclass>
(2.2)父类,子类都映射一张表
<joined-subclass name="" table="">
<key column=""/>
<property name="" type=""></property>
<joined-subclass>
(2.2)每个子类都映射一张表
<id name="">
<generator class="不能为自增长主键生成器"></generator>
</id>
<union-subclass name="" table="">
<property name="" type=""></property>
</union-subclass>
相关文章推荐
- javaEE 用户、部门、角色、权限实体的关系设计与hibernate映射配置文件关系总结
- Hibernate相关配置文件、映射文件案例、工具类、总结相关
- Hibernate4学习总结(2)--配置形式的集合映射,关联关系映射
- Hibernate学习笔记二:常用映射配置
- hibernate课程 初探单表映射2-2 hibernate常用配置
- SpringMVC_v02中的总结(web项目、java项目中引入Config.properties,加载hibernate映射文件的配置的区别)
- hibernate配置文档常用配置、hbm配置文件(对象-关系映射)的基本配置
- 【极客营】Hibernate常用的配置文件-映射配置文件
- hibernate集合映射set和list配置总结
- hibernate课程 初探单表映射2-7 hbm配置文件常用设置
- Hibernate入门学习(4)----Hibernate配置文档常用总结
- Hibernate 配置文件与映射文件 总结
- SSH——Hibernate继承关系映射详解(配置+实例+总结)
- hibernate 各种映射的配置文件总结
- Hibernate配置文件中映射元素详解
- 10-hibernate.cfg.xml配置总结
- Hibernate配置文件中映射元素详解
- Hibernate配置文件中映射元素详解
- Cisco AP 常用配置总结 推荐
- hibernate映射总结详解: 映射一对多双向自身关联关系