首先我们以一个例子来说明:
ITEM 与IMAGE(假设有多个字段比如name path size,item_id 等)
显然它们是一对多的关系,要实现它们的关联
则需在ITEM中需要加入一个集合类映射
这里牵涉到两种办法来解决这个问题,hibernate中有两种类型,实体和值类型。所以
第一:当用实体类型时其实就是用<one- to -many>即:item映射文件中加入:
<set name="image" table="image">
<key column="item_id"></key>
<one-to-many class="Image">
</set>
第二:当使用值类型时,则需要使用到组件的结合
即:item映射文件中加入:
<set name="image" table="image">
<key column="item_id"/>
<composite-element class="Image">
<property name="name" column=""/>
...
</composite-element >
</set>
这两者都可以实现ITEM和IMAGE的关联,但是区别就在第2中的IMAGE不是一个实体类(持久化类),没有标识符。使用所有字段作为联合主键。
显然在实际中第一种应该会用到多些,我想不通“值类型的集合映射”在哪里有应用场景?
分享到:
相关推荐
2,建立表的hibernate支持,生成tb_user类和对应的配置文件 3,修改配置文件使之和相应的类对应, 4,修改tb_user类,创建一个set类型的字段emailes,生成它的set和get方法 5,写测试类,对以上内容进行测试。 二、...
里面有所有hibernate 多种映射的代码:继承映射,实体映射,集合类映射等很全,适合初学者。
hibernate pdf 电子书 hibernate 入门 基本配置 持久化类 集合类 映射 事务和并发
Hibernate可以将Java中几个内置的集合结构映射为数据库使用的关系模型,下面我们就来看一下Java的Hibernate框架中集合类数据结构的映射编写教程:
6. 集合类(Collections)映射 6.1. 持久化集合类(Persistent collections) 6.2. 集合映射( Collection mappings ) 6.2.1. 集合外键(Collection foreign keys) 6.2.2. 集合元素(Collection elements) 6.2.3. ...
Hibernate3.2官方中文参考手册,内容涉及Hibernate入门知识、配置、集合类映射、关联关系映射、组件、事务并发、批量处理、对象事件等知识。
每个具体类映射成一张表(hibernate_extends_3) 25 组件component映射(hibernate_component) 27 复合(联合)主键映射(hibernate_composite) 27 集合(collection)映像 (hibernate_collection) 28 Hibernate 对...
3.4.2 把Customer持久化类映射到CUSTOMERS表 3.5 通过Hibernate API操纵数据库 3.5.1 Hibernate的初始化 3.5.2 访问Hibernate的Session接口 3.6 运行helloapp应用 3.6.1 创建运行本书范例的系统环境 ...
6. 集合类(Collections)映射 6.1. 持久化集合类(Persistent collections) 6.2. 集合映射( Collection mappings ) 6.2.1. 集合外键(Collection foreign keys) 6.2.2. 集合元素(Collection elements) 6.2.3. ...
6. 集合类(Collections)映射 6.1. 持久化集合类(Persistent collections) 6.2. 集合映射( Collection mappings ) 6.2.1. 集合外键(Collection foreign keys) 6.2.2. 集合元素(Collection elements) 6.2.3. ...
6、集合类映射 7、组件映射 8、继承映射 9、操作持久化数据 10、事务和并行 11、Hibernate查询语言 12、条件查询 13、原生SQL查询 14、性能提升 15、工具箱指南 16、示例:父子关系 17、示例:Weblog应用程序 18、...
6. 集合类(Collections)映射 6.1. 持久化集合类(Persistent collections) 6.2. 集合映射( Collection mappings ) 6.2.1. 集合外键(Collection foreign keys) 6.2.2. 集合元素(Collection elements) 6.2.3. ...
集合类(Collections)映射 6.1. 持久化集合类(Persistent Collections) 6.2. 映射集合(Mapping a Collection) 6.3. 值集合和多对多关联(Collections of Values and Many-To-Many Associations) 6.4. ...
6. 集合类(Collections)映射 6.1. 持久化集合类(Persistent collections) 6.2. 集合映射( Collection mappings ) 6.2.1. 集合外键(Collection foreign keys) 6.2.2. 集合元素(Collection elements) 6.2.3. 索引...
1.Hiberante入门 2.体系结构 3.配置 4.持久化类 5.对象/关系数据库映射基础 6.集合类映射 7.关联关系映射 。。。
6. 集合类(Collections)映射; 7. 关联关系映射; 8. 组件(Component)映射; 9. 继承映射(Inheritance Mappings); 10. 与对象共事; 11. 事务和并发; 12. 拦截器与事件(Interceptors and events); 13. 批量处理(Batch...
4.3 类映射选项 4.3.1 动态的SQL生成 4.3.2 使实体不可变 4.3.3 给查询命名实体 4.3.4 声明包名称 4.3.5 用引号把SQL标识符括起来 4.3.6 实现命名约定 4.4 细粒度的模型和映射 ...
Hibernate Annotations API 中文文档 前言 1. 创建一个注解项目 1.1. 系统需求 1.2. 系统配置 2. 实体Bean 2.1. 简介 2.2. 用EJB3注解进行映射 2.2.1. 声明实体bean 2.2.1.1. 定义表(Table) 2.2.1.2. 乐观...
6. 集合类(Collections)映射 6.1. 持久化集合类(Persistent collections) 6.2. 集合映射( Collection mappings ) 6.2.1. 集合外键(Collection foreign keys) 6.2.2. 集合元素(Collection elements) 6.2.3. ...