- 浏览: 1191467 次
- 性别:
- 来自: 广州
文章分类
- 全部博客 (883)
- Spring (101)
- Swing (1)
- Mysql (21)
- Js (59)
- Jsp (2)
- Hibernate (19)
- Myeclipse (5)
- SqlServer 2000 (2)
- poi (15)
- Java (70)
- SSH (12)
- Html (47)
- Fusion Charts (1)
- C\C++ (2)
- 汇编 (36)
- Jquery (37)
- Struts2 (6)
- Ubuntu (16)
- powerDesinger (4)
- Jboss (3)
- JAX-RS (13)
- JAXB (5)
- JAX-WS (11)
- JMS (4)
- WebSocket (8)
- PHP (16)
- Flash (1)
- maven (3)
- Oracle (8)
- HttpClient (6)
- sqlserver (19)
- svn (5)
- Tomcat (3)
- Jdbc (3)
- EsayUi (11)
- 微信公众平台 (19)
- IIS (2)
- Freemarker (11)
- Comet (1)
- Spring MVC (85)
- JBoss Seam (3)
- 二维码 (9)
- Spring Security (4)
- Ehcache (3)
- Apache Shiro (7)
- jackson (16)
- JPA (8)
- jcaptcha (2)
- RSA (2)
- Ajax (6)
- 跟我学Shiro (0)
- Spring4 (19)
- 跟我学spring3 (0)
- css (32)
- excel (4)
- Filter (3)
- 微信公众帐号开发教程 (0)
- Android (6)
- log4j (6)
- 淘宝接口 (17)
- 支付集成 (3)
- 单点登录 (3)
- Html5 (27)
- 移动平台前端 (3)
- Linux (44)
- FusionCharts (27)
- Json Jackson Xml (5)
- 方培工作室-微信开发 (0)
- Apache与Tomcat与IIS整合 (10)
- Nginx (17)
- webService (2)
- apache (4)
- lucene (3)
- lodop (2)
- Shiro (3)
- zTree (2)
- ireport (12)
- Servlet3.0 (5)
- 前端美工 (19)
- AngularJS (1)
- C#开发微信门户及应用 (0)
- Shell (3)
- bat脚本 (16)
- Bootstrap (26)
- Less (10)
- photoshop (6)
- Redis (6)
- Mongodb (10)
- MyBatis (3)
- 数据结构 (0)
- 读写分离-主从复制 (0)
- JFinal (0)
- 百度地图api (3)
- hadoop-hbase-hive-spark (3)
- WebStorm (2)
- Quartz (5)
- ios (0)
- Mina (8)
- Android Studio (4)
- Ratchet教程 (0)
- 移动端重构系列 (1)
- cubic-bezier贝塞尔曲线CSS3动画工具 (1)
- nginx+tomcat+memcached集群 (0)
- 集群 (0)
- ZooKeeper (3)
- Dubbo (0)
- vpn (0)
- kafka (0)
- JVM垃圾回收机制 (0)
- 微信小程序 (0)
- Lua (0)
- Hystrix (0)
- Vue.js (0)
- mycat (0)
- Openresty (0)
- springBoot (0)
- 新分类 (0)
- guava (0)
- 大数据 (0)
- Sentinel (0)
最新评论
-
JackMacing:
中文怎么解决?
SpringMVC与iReport(JasperReports) 5.6整合开发实例 -
18335864773:
用pageoffice把.可以实现在线的文档操作.直接转pdf ...
转:使用jasperreport动态生成pdf,excel,html -
linhao0907:
推荐一款轻量开源的支付宝组件:https://github.c ...
关于Alipay支付宝接口(Java版) -
songronghu:
太好了,非常有用,谢谢分享~
Java ConcurrentModificationException 异常分析与解决方案 -
wzwahl36:
http://www.atool.org/json2javab ...
Java下利用Jackson进行JSON解析和序列化
多对一(many to one)
单向many-to-one关联是最常见的单向关联关系。
<class name="Person">
<id name="id" column="personId"><generator class="native"/></id>
<many-to-one name="address" column="addressId" not-null="true"/>
</class>
<class name="Address">
<id name="id" column="addressId"><generator class="native"/></id>
</class>
create table Person ( personId bigint not null primary key, addressId bigint not null )
create table Address ( addressId bigint not null primary key
基于外键关联的单向一对一关联和单向多对一关联几乎是一样的。唯一的不同就是单向一对一关联中的外键字段具有唯一性约束。
<class name="Person">
<id name="id" column="personId"><generator class="native"/></id>
<many-to-one name="address" column="addressId" unique="true" not-null="true"/>
</class>
<class name="Address">
<id name="id" column="addressId"><generator class="native"/></id>
</class>
create table Person ( personId bigint not null primary key, addressId bigint not null unique )
create table Address ( addressId bigint not null primary key )
基于主键关联的单向一对一关联通常使用一个特定的id生成器。(请注意,在这个例子中我们掉换了关联的方向。)
<class name="Person">
<id name="id" column="personId"><generator class="native"/></id>
</class>
<class name="Address">
<id name="id" column="personId"><generator class="foreign">
<param name="property">person</param></generator></id>
<one-to-one name="person" constrained="true"/>
</class>
create table Person ( personId bigint not null primary key )
create table Address ( personId bigint not null primary key )
基于外键关联的单向一对多关联是一种很少见的情况,并不推荐使用。
<class name="Person">
<id name="id" column="personId"><generator class="native"/></id>
<set name="addresses">
<key column="personId" not-null="true"/>
<one-to-many class="Address"/></set>
</class>
<class name="Address">
<id name="id" column="addressId"><generator class="native"/></id>
</class>
create table Person ( personId bigint not null primary key )
create table Address ( addressId bigint not null primary key, personId bigint not null )
我们认为对于这种关联关系最好使用连接表。
8.3. 使用连接表的单向关联(Unidirectional associations with join tables)
基于连接表的单向一对多关联 应该优先被采用。请注意,通过指定unique="true",我们可以把多样性从多对多改变为一对多。
<class name="Person">
<id name="id" column="personId"><generator class="native"/></id>
<set name="addresses" table="PersonAddress">
<key column="personId"/>
<many-to-many column="addressId" unique="true" class="Address"/></set>
</class>
<class name="Address">
<id name="id" column="addressId"><generator class="native"/></id>
</class>
create table Person ( personId bigint not null primary key )
create table PersonAddress ( personId not null, addressId bigint not null primary key )
create table Address ( addressId bigint not null primary key )
基于连接表的单向多对一关联在关联关系可选的情况下应用也很普遍。
<class name="Person">
<id name="id" column="personId"><generator class="native"/></id>
<join table="PersonAddress" optional="true">
<key column="personId" unique="true"/>
<many-to-one name="address" column="addressId" not-null="true"/></join>
</class>
<class name="Address">
<id name="id" column="addressId"><generator class="native"/></id>
</class>
create table Person ( personId bigint not null primary key )
create table PersonAddress ( personId bigint not null primary key, addressId bigint not null )
create table Address ( addressId bigint not null primary key )
基于连接表的单向一对一关联非常少见,但也是可行的。
<class name="Person">
<id name="id" column="personId"><generator class="native"/></id>
<join table="PersonAddress" optional="true">
<key column="personId" unique="true"/>
<many-to-one name="address" column="addressId" not-null="true" unique="true"/>
</join>
</class>
<class name="Address">
<id name="id" column="addressId"><generator class="native"/></id>
</class>
create table Person ( personId bigint not null primary key )
create table PersonAddress ( personId bigint not null primary key, addressId bigint not null unique )
create table Address ( addressId bigint not null primary key )
最后,还有 单向多对多关联.
<class name="Person">
<id name="id" column="personId"><generator class="native"/></id>
<set name="addresses" table="PersonAddress">
<key column="personId"/>
<many-to-many column="addressId" class="Address"/>
</set>
</class>
<class name="Address">
<id name="id" column="addressId"><generator class="native"/></id>
</class>
create table Person ( personId bigint not null primary key )
create table PersonAddress ( personId bigint not null, addressId bigint not null, primary key (personId, addressId) )
create table Address ( addressId bigint not null primary key )
8.4. 双向关联(Bidirectional associations)
8.4.1. 一对多(one to many) / 多对一(many to one)
双向多对一关联 是最常见的关联关系。(这也是标准的父/子关联关系。)
<class name="Person">
<id name="id" column="personId"><generator class="native"/></id>
<many-to-one name="address" column="addressId" not-null="true"/>
</class>
<class name="Address">
<id name="id" column="addressId"><generator class="native"/></id>
<set name="people" inverse="true">
<key column="addressId"/>
<one-to-many class="Person"/></set>
</class>
create table Person ( personId bigint not null primary key, addressId bigint not null )
create table Address ( addressId bigint not null primary key )
基于外键关联的双向一对一关联也很常见。
<class name="Person">
<id name="id" column="personId"><generator class="native"/></id>
<many-to-one name="address" column="addressId" unique="true"not-null="true"/>
</class>
<class name="Address">
<id name="id" column="addressId"><generator class="native"/></id>
<one-to-one name="person" property-ref="address"/>
</class>
create table Person ( personId bigint not null primary key, addressId bigint not null unique )
create table Address ( addressId bigint not null primary key )
基于主键关联的一对一关联需要使用特定的id生成器。
<class name="Person">
<id name="id" column="personId"><generator class="native"/></id>
<one-to-one name="address"/>
</class>
<class name="Address">
<id name="id" column="personId">
<generator class="foreign">
<param name="property">person</param></generator></id>
<one-to-one name="person" constrained="true"/>
</class>
create table Person ( personId bigint not null primary key )
create table Address ( personId bigint not null primary key )
8.5. 使用连接表的双向关联(Bidirectional associations with join tables)
8.5.1. 一对多(one to many) /多对一( many to one)
基于连接表的双向一对多关联。注意inverse="true"可以出现在关联的任意一端,即collection端或者join端。
<class name="Person">
<id name="id" column="personId"><generator class="native"/></id>
<set name="addresses" table="PersonAddress">
<key column="personId"/>
<many-to-many column="addressId" unique="true" class="Address"/></set>
</class>
<class name="Address">
<id name="id" column="addressId"><generator class="native"/></id>
<join table="PersonAddress" inverse="true" optional="true">
<key column="addressId"/>
<many-to-one name="person" column="personId" not-null="true"/></join>
</class>
create table Person ( personId bigint not null primary key )
create table PersonAddress ( personId bigint not null, addressId bigint not null primary key )
create table Address ( addressId bigint not null primary key )
基于连接表的双向一对一关联极为罕见,但也是可行的。
<class name="Person">
<id name="id" column="personId"><generator class="native"/></id>
<join table="PersonAddress" optional="true">
<key column="personId" unique="true"/>
<many-to-one name="address" column="addressId" not-null="true" unique="true"/>
</join>
</class>
<class name="Address">
<id name="id" column="addressId"><generator class="native"/></id>
<join table="PersonAddress" optional="true" inverse="true">
<key column="addressId" unique="true"/>
<many-to-one name="address" column="personId" not-null="true" unique="true"/>
</join>
</class>
create table Person ( personId bigint not null primary key )
create table PersonAddress ( personId bigint not null primary key, addressId bigint not null unique )
create table Address ( addressId bigint not null primary key )
最后,还有 双向多对多关联.
<class name="Person">
<id name="id" column="personId"><generator class="native"/></id>
<set name="addresses">
<key column="personId"/>
<many-to-many column="addressId" class="Address"/></set>
</class>
<class name="Address">
<id name="id" column="addressId"><generator class="native"/></id>
<set name="people" inverse="true">
<key column="addressId"/>
<many-to-many column="personId" class="Person"/></set>
</class>
create table Person ( personId bigint not null primary key )
create table PersonAddress ( personId bigint not null, addressId bigint not null, primary key (personId, addressId) )
create table Address ( addressId bigint not null primary key )
发表评论
-
易百教程
2017-06-07 14:00 0http://www.yiibai.com/lua/l ... -
Hibernate原生SQL查询
2017-04-10 14:20 0http://blog.csdn.net/houpe ... -
Hibernate Shards 数据的水平、垂直切割
2016-08-13 10:29 0http://www.cnblogs.com/RicC ... -
DBCP,CP30,proxool连接池在spring hibernate中的配置
2015-07-13 11:16 0Java代码 用spring默认的连接 ... -
操作EntityManager
2015-03-01 10:31 4517操作EntityManager Interacting ... -
EntityManager实体操作
2015-03-01 10:24 677EntityManager 持久化实体 persi ... -
Could not write JSON: Infinite recursion (StackOverflowError) (through reference
2015-02-23 23:09 4662jackson 中的@JsonBackReference和@ ... -
jackson转换json出现无限递归问题
2015-02-23 23:07 4455环境:springmvc+hibernate+json ... -
hibernate的速度问题--hibernate.jdbc.fetch_size和 hibernate.jdbc.batch_size
2015-01-28 12:48 2066这点我也疑惑过,最初应用hibernate的项 ... -
Java泛型的使用以及注入DAO --由SpringSide想到的
2014-11-05 09:02 885DAO层的BaseHibernateDao类支持泛型,其目 ... -
宿舍管理系统
2012-03-04 00:26 1882项目名称 宿舍管理系统 开发工具 MyEclipse6.0+ ... -
S2SH问题点
2012-03-02 14:29 856Struts2: 为什么每次请 ... -
[转载]最新SpringMVC + spring3.1.1 + hibernate4.1.0 集成及常见问题总结
2012-02-28 09:51 1669下载地址 一 开发环境 1、动态web工程 ... -
Hiberante annotation 设置延迟加载
2011-10-13 09:24 916@ManyToMany(fetch = FetchType.L ... -
Hibernate -- 注解(Annotation)关系映射
2011-10-11 13:23 27411. Hibernate Annotation关系 ... -
struts2.1.6+hibernate3.3+spring3.0遇到的问题
2011-09-27 17:00 4987struts2.1.6+hibernate3.3+spring ... -
使用 Spring 2.5 注释驱动的 IoC 功能
2011-09-21 15:43 593概述 注释配置相对于 XML 配置具有很多的优势: 它可 ... -
Hibernate的SQL查询
2011-09-21 09:34 1018Hibernate还支持使用SQL查询,使用SQL查询可以利用 ... -
Hibernate使用sql语句查询
2011-09-21 09:29 886import java.util.Iterator; imp ... -
org.hibernate.AnnotationException: No identifier specified for entity
2011-09-15 10:51 1004org.hibernate.AnnotationExcepti ...
相关推荐
在hibernate中,通常配置对象关系映射关系有两种,一种是基于xml的方式,另一种是基于annotation的注解方式,熟话说,萝卜青菜,可有所爱,每个人都有自己喜欢的配置方式,这个是xml配置的例子
关于hibernate3.0各种数据库关联的小列子,里面的内容分的很仔细很有条理。对于初学者很有帮助。
Hibernate双向一对一关联映射(注解版)
由于上传最大是60m,这里只是上传关联的配置xml和实体类,环境搭建自己找度娘解决
在hibernate中,通常配置对象关系映射关系有两种,一种是基于xml的方式,另一种是基于annotation的注解方式,熟话说,萝卜青菜,可有所爱,每个人都有自己喜欢的配置方式,我在试了这两种方式以后,发现使用...
Hibernate配置 1.2.4. 用Ant构建 1.2.5. 启动和辅助类 1.2.6. 加载并存储对象 1.3. 第二部分 - 关联映射 1.3.1. 映射Person类 1.3.2. 单向Set-based的关联 1.3.3. 使关联工作 1.3.4. 值类型的集合 1.3.5...
详细的介绍hibernate的所有配置映射、事务、xml的配置、多态查询、关联等核心中文帮助,提供源代码参考
数据日志:设计中提供数据日志注入接口,管理数据日志注入,业务系统可过基于hibernate Listener 拦截数据表操作,注入数据日志(此为业务系统实现,设计中提供数据日志注入接口),提供 日志管理:通过统一的...
这是第二篇, 内容如下:Hibernate配置文件;jdbc.fetch_size;jdbc.batch_size; POJO 类和数据库的映射文件*.hbm.xml;主键生成策略generator;映射集合属性;延迟加载策略;映射组件属性;关联关系映射:双向 1-N;继承...
1.2.3. Hibernate配置 1.2.4. 用Ant构建 1.2.5. 启动和辅助类 1.2.6. 加载并存储对象 1.3. 第二部分 - 关联映射 1.3.1. 映射Person类 1.3.2. 单向Set-based的关联 1.3.3. 使关联工作 1.3.4. 值类型的集合 ...
1.2.3. Hibernate配置 1.2.4. 用Ant构建 1.2.5. 启动和辅助类 1.2.6. 加载并存储对象 1.3. 第二部分 - 关联映射 1.3.1. 映射Person类 1.3.2. 单向Set-based的关联 1.3.3. 使关联工作 1.3.4. 值类型的集合 ...
1.2.3. Hibernate配置 1.2.4. 用Ant构建 1.2.5. 启动和辅助类 1.2.6. 加载并存储对象 1.3. 第二部分 - 关联映射 1.3.1. 映射Person类 1.3.2. 单向Set-based的关联 1.3.3. 使关联工作 1.3.4. 值类型的集合 ...
两种配置文件: A.hibernate.cfg.xml 和 B.hibernate.properties A中可含映射文件的配置,而B中hard codes加映射文件。 A。Configuration config=new Configuration().config(); B. ...
前言 1. 翻译说明 2. 版权声明 1. Hibernate入门 1.1. 前言 1.2. 第一部分 - 第一个Hibernate应用...3.7. XML配置文件 3.8. J2EE应用程序服务器的集成 3.8.1. 事务策略配置 3.8.2. JNDI绑定的SessionFactory
2) 在hibernate.cfg.xml文件中加入EhCache缓存插件的提供类。 <!--配置缓存插件 --> <property name="hibernate.cache.provider_class"> org.hibernate.cache.EhCacheProvider 3) 挎贝ehcache.xml文件到类...
1.2. 系统配置 2. 实体Bean 2.1. 简介 2.2. 用EJB3注解进行映射 2.2.1. 声明实体bean 2.2.1.1. 定义表(Table) 2.2.1.2. 乐观锁定版本控制 2.2.2. 映射简单属性 2.2.2.1. 声明基本的属性映射 2.2.2.2. 声明列...
1.2.3. Hibernate配置 1.2.4. 用Ant构建 1.2.5. 启动和辅助类 1.2.6. 加载并存储对象 1.3. 第二部分 - 关联映射 1.3.1. 映射Person类 1.3.2. 单向Set-based的关联 1.3.3. 使关联工作 1.3.4. 值类型的集合 ...
3.1 创建Hibernate的配置文件 3.2 创建持久化类 3.3 创建数据库Schema 3.4 创建对象-关系映射文件 3.4.1 映射文件的文档类型定义(DTD) 3.4.2 把Customer持久化类映射到CUSTOMERS表 3.5 通过...
1.2.3. Hibernate配置 1.2.4. 用Ant构建 1.2.5. 启动和辅助类 1.2.6. 加载并存储对象 1.3. 第二部分 - 关联映射 1.3.1. 映射Person类 1.3.2. 单向Set-based的关联 1.3.3. 使关联工作 1.3.4. 值类型的集合 ...
2.1.3 Hibernate配置和启动 2.1.4 运行和测试应用程序 2.2 启动Java Persistence项目 2.2.1 使用Hibernate Annotations 2.2.2 使用Hibernate EntityManager 2.2.3 引入EJB组件 2.2.4 切换...