有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] Nuts & Bolts Problem 螺栓螺母问题

    Given a set of n nuts of different sizes and n bolts of different sizes. There is a one-one mapping ...

  2. 类库,委托,is和as运算符,泛型集合

    类库:其实就是一堆类文件,只不过用户看不到这些类的源代码,保密性好. 优点:保密性好缺点:如果这个方法不好用,使用者无法自己去更改它. 类文件是.cs    类库是.dll 新建项目为类库,在debu ...

  3. html中隐藏域hidden的作用介绍及使用示例

    基本语法: <input type="hidden" name="field_name" value="value"> 作用:  ...

  4. css重新认识(2)

    1)行内元素可以用margin-left与margin-right调整位置,但用margin-top与margin-bottom来调整位置不会有效果,只有具有block属性值后才能像块级元素般被外边距 ...

  5. SQL servcer 时间日期函数、数据类型转换

    1.时间日期函数 2.数据类型转换 3.习题 建立两个表,一个部门表,一个人员表.部门:部门的编号,部门的名称,部门的职责.人员:人员的编号,姓名,年龄,性别,cid所属部门

  6. 示例Oracle 10.2.0.1.0升级到10.2.0.4.0一例

    1.查看当前系统版本 [oracle@std Disk1]$ sqlplus '/as sysdba' SQL*Plus: Release - Production on Thu Jan :: Cop ...

  7. Cocos2d-x 开发 v3.2 建立新项目并添加库文件

    一.添加其它类库     3.0以上的设计耦合性强,项目中模块常以库的形式存在,需常添加链接库.在3.0中经常用到CocoStudio 编辑器的资源数据,所以需要添加CocoStudio 库. 1.1 ...

  8. 屏蔽Enter触发的事件

    无论是 <button type="button" onclick="console.log('123');">123</button> ...

  9. java 中的2个接口 Comparable和Comparator

    像Integer.String这些类型的数据都是已经实现Comparable接口的,所以对这些类型可以直接通过Arrays.sort(...)和Collections.sort(...)方法进行排序. ...

  10. 真机调试---打包6plus出现问题

    问题: dyld: Library not loaded: @rpath/libswiftCore.dylib Referenced from: /private/var/mobile/Contain ...