有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. 打开FileGeoDatabase中要素类

    private IFeatureClass OpenFileGdbFtCls(string fn) { IFeatureClass pftcls = null; IWorkspaceFactory w ...

  2. poj 2325 Persistent Numbers

    简单的贪心和高精度运算,主要还是要读懂题. #include"iostream" #include"stdio.h" #include"string& ...

  3. ajax异步验证用户名密码,提示路径错误

    使用thinkphp框架异步验证用户名和密码的时候,ajax路径错误可能有多重情况.我遇到的是,我自感路径没问题,且先前使用无错.由于多人合作使用svn,所以在更新代码后,使用firebug显示一直是 ...

  4. CentOs5.8下安装Oracle12C

    12C安装向导: http://docs.oracle.com/database/121/LTDQI/toc.htm 12C下载地址: http://www.oracle.com/technetwor ...

  5. javascript遍历数组最优写法

    var arr = [];//这样定义的数组,是null,等待开辟空间 var arr = new Array();//不建议使用,会占用一块内存空间 var i=0,len=arr.length; ...

  6. JPA入门例子(采用JPA的hibernate实现版本)

    (1).JPA介绍: JPA全称为Java Persistence API ,Java持久化API是Sun公司在Java EE 5规范中提出的Java持久化接口.JPA吸取了目前Java持久化技术的优 ...

  7. Ajax Post 与 Get 实例

    Ajax的POST实例,index.html <html> <head> <script type="text/javascript"> fun ...

  8. ping过程

    premise: 一个局域网内,网段为192.168.0.0 , 有两台主机A(192.168.0.3) 主机B(192.168.0.4) 1. A 机器上执行: ping 192.168.0.4 2 ...

  9. EmguCV 阈值化

    一.public static double cvThreshold( IntPtr src, IntPtr dst, double threshold, double maxValue, //Max ...

  10. 【iCore3 双核心板_FPGA】例程十三:FSMC总线通信实验——复用地址模式

    实验指导书及代码包下载: http://pan.baidu.com/s/1nuYpI8x iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...