有3个对象,对象A,对象B,对象C。他们的实体关系为:

1、A中存在List<B>和List<C>,即一个包含另外两个;

2、A中存在List<B>,B中存在List<C>,即传递关系;

存在上面2种情况,并且fetch=eager就会报上面的异常。解决办法:

方式1、将List改成Set;

方式2、将fetch改成lazy方式;

方式3、利用Hibernate注解:@IndexColumn

方式4、利用JPA的注解:@OrderColumn

上面方式3和4原理都一样,而方式3是Hibernate专用的,建议用方式4。

3、利用上面方式3或者4获取到的结果,比如A与B为1对多关系,而B在数据库中有3条符合条件的记录,但是查询出结果A中的List<B>有4个元素,

第一个为null,没搞明白是为什么。

4、一般而言,没有特别的需求,都用Set就好了。

5、我这里纠结是因为dubbo的默认rpc工具hessian的反序列化对Set的支持不友好。所以才有了这么个矛盾的关系。

Caused by: org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags的更多相关文章

  1. cannot simultaneously fetch multiple bags

    问题是什么时候出现的呢?    当一个实体对象中包含多于一个non-lazy获取策略时,比如@OneToMany,@ManyToMany或者@ElementCollection时,获取策略为(fetc ...

  2. Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.cache.ehcache.EhCacheRegionFactory] as strategy [org.hibernate.cache.spi.RegionFac

    警告: Exception encountered during context initialization - cancelling refresh attempt: org.springfram ...

  3. Caused by: org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set

    docs.jboss.org文档示例代码:(http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/) sta ...

  4. SSH框架-Caused by: org.hibernate.MappingException: column attribute may not be used together with <column> subelement

    昨晚修改了一些表关系,在相关的hbm.xml文件中做了改动,今天早上起来启动tomcat后,发现项目启动不了,控制台报错: 2015-6-14 9:09:42 org.apache.catalina. ...

  5. Caused by:org.hibernate.HibernateException:Unable to make JDBC Connection

    1.错误描述 Caused by:org.hibernate.HibernateException:Unable to make JDBC Connection[jdbc\:mysql\://loca ...

  6. Caused by:org.hibernate.MappingNotFoundException:resouce:com/you/model/Monkey.hbm.xml not found

    1.错误描述 Caused by:org.hibernate.MappingNotFoundException:resouce:com/you/model/Monkey.hbm.xml not fou ...

  7. Caused by:org.hibernate.DuplicateMappingException:Duplicate class/entity/ mapping

    1.错误描述 java.lang.ExceptionInInitializerError Caused by:org.hibernate.InvalidMappingException:Could n ...

  8. SSH执行hql报错:Caused by: org.hibernate.hql.ast.QuerySyntaxException: user is not mapped [from user where username = ?]

    报错信息: ERROR Dispatcher:38 - Exception occurred during processing request: user is not mapped [from u ...

  9. Caused by: org.hibernate.HibernateException: identifier of an instance of ... is alterde from

    Caused by: org.hibernate.HibernateException: identifier of an instance of ... is alterde from     Hi ...

随机推荐

  1. [LintCode] Swap Nodes in Pairs 成对交换节点

    Given a linked list, swap every two adjacent nodes and return its head.   Example Given 1->2-> ...

  2. Hibernate---单条记录的增删改查

    package com.hanqi.test; import static org.junit.Assert.*; import java.util.Date; import org.hibernat ...

  3. IE hack中主要的几个

    _: IE6; #*+.: IE6 IE7; black\0: IE8; black\9: IE所有; @media screen\9 { … }: IE6 IE7; @media \0screen\ ...

  4. Uncaught SyntaxError: Unexpected token ILLEGAL

    原因,相关的JS函数中,存在一个中文逗号,修改即可正常执行

  5. HTML--JS练习小游戏(别踩白块儿)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. Canvas 属性,方法

      context . restore() //弹出堆最上面保存的绘图状态 context . save() //在绘图状态堆上保存当前绘图状态 绘图状态可以看作当前画面应用的所有样式和变形的一个快照 ...

  7. document.body.clientHeight 和 document.documentElement.clientHeight的区别

    document.body.clientWidth ==> BODY对象宽度document.body.clientHeight ==> BODY对象高度document.document ...

  8. vbox下Oracle Enterprise liunx5.4虚拟机安装10G RAC实验(一)

    1.配置第一个虚拟机 1.1 安装后的登录界面 1.2 第1台机器(单数据配置方面) 1.2.1 验证安装包 1.2.2 修改内核参数 1.2.3添加安全限制 1.2.4关闭防火墙 1.2.5添加用户 ...

  9. nba技能表

    球员名 主动技能名 主动技能效果 拆解技能名 拆解技能效果 巅峰-纳什 跑投三分 全队三分出手概率提高X%,但体力消耗增加Y% 稳固进攻 全队进攻增加X%,持续整场比赛 巅峰-科比 肉搏 对方全体行动 ...

  10. ubuntu 安装 nodejs

    http://blog.csdn.net/caib1109/article/details/51804687 我的系统环境: Ubuntu 16.04 64位 本文内容亲测可用, 请放心食用 使用淘宝 ...