我出现问题如下:
org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags
at org.hibernate.loader.BasicLoader.postInstantiate(BasicLoader.java:94)
at org.hibernate.loader.entity.EntityLoader.<init>(EntityLoader.java:119)
at org.hibernate.loader.entity.EntityLoader.<init>(EntityLoader.java:71)
at org.hibernate.loader.entity.EntityLoader.<init>(EntityLoader.java:54)
at org.hibernate.loader.entity.BatchingEntityLoader.createBatchingEntityLoader(BatchingEntityLoader.java:133)
at org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:1914)
at org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:1937)
at org.hibernate.persister.entity.AbstractEntityPersister.createLoaders(AbstractEntityPersister.java:3205)
at org.hibernate.persister.entity.AbstractEntityPersister.postInstantiate(AbstractEntityPersister.java:3191)
at org.hibernate.persister.entity.SingleTableEntityPersister.postInstantiate(SingleTableEntityPersister.java:728)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:348)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872)
at com.fzb.flashShopping.entity.EntityTest.testSchemaExport(EntityTest.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
问题是什么时候出现的呢?
当一个实体对象中包含多于一个non-lazy获取策略时,比如@OneToMany,@ManyToMany或者@ElementCollection时,获取策略为(fetch = FetchType.EAGER)
出现问题的原因:
当(fetch = FetchType.EAGER)多余一个时,持久框架抓取一方的对象时,同时又将多方的对象加载进容器中,多方又可能关联其它对象,Hibernate实现的JPA,默认最高抓取深度含本身级为四级(它有个属性配置是0-3),若多方(第二级)存在重复值,则第三级中抓取的值就无法映射,就会出现 multiple bags。
解决方法:
1、将(fetch = FetchType.EAGER)改为(fetch = FetchType.LAZY)
2、将List修改成Set集合,即推荐@ManyToMany或@OneToMany的Many方此时用Set容器来存放,而不用List集合。
3、改变FetchMode为@Fetch(FetchMode.SUBSELECT),即发送另外一条select语句抓取前面查询到的所有实体对象的关联实体。
4、在对应的属性上添加@IndexColumn,该注解允许你指明存放索引值的字段,目的跟Set容器不允许重复元素的道理一样。
推荐的处理办法:
方法2;
方法3和方法4是Hibernate特有的,非JPA标准;
如果可以用方法1,那就不会出现这个问题。
参考:
1、http://blog.eyallupu.com/2010/06/hibernate-exception-simultaneously.html
2、http://dyldragon.iteye.com/blog/788385
3、http://howsun.blog.sohu.com/119020926.html
相关推荐
Differential absorption lidar (DIAL) has ... In this paper, a simple and accurate algorithm is presented for simultaneously detecting and estimating multiple vapor materials with multiple-wavelength DI
传统的解决偏差问题的方法主要分为两类:一是将问题框架化为强化学习,二是量化偏差并重新加权损失函数。然而,这些方法都有其局限性。论文作者们设计了一种不同的策略,他们的ANN模型能够创建一个对偏差不变的数据...
为解决这一问题,文章介绍了一种新开发的工业级体积脉动注射成型(VPIM)机,该机能够在整个注射成型过程中引入高强度振动场。作为一种一步成型的微观结构控制手段,振动场能够驱动分散的PET微滴形成刚性的微纤维,...
聚合物加工中的自强化和自增韧是指在不损害材料流动性的情况下,通过物理或化学方法提高聚合物的力学性能,如冲击强度和屈服强度等。高密度聚乙烯(HDPE)作为一种常见的工程塑料,其优异的化学稳定性、良好的加工性...
本文讨论的是一类三维逆几何问题,即形状识别问题,主要关注的是同时估计复合域中两个界面配置的问题。复合域指的是由三个不同区域构成的区域。在研究中,使用了共轭梯度法(Conjugate Gradient Method, CGM)和商业...
This paper combines workspace models with optimization techniques to simultaneously address wholearm collision avoidance, joint limits and camera field of view (FOV) limits for vision-based motion ...
尽管如此,文章提出了一系列可能寻找这类物质的方法和理论依据。 关于这类物质的独特属性,理论推断它们可能与普通的正电常数和正磁导率物质有着根本不同的电磁响应特性,这在理论上可能开启一系列新的物理现象和...
这篇论文探讨的是一对多充电模式——即一个移动充电器同时为多个传感器充电,从而有效解决了传感器网络中充电的可扩展性和效率问题。 首先,论文提出了一种新型的充电技术,即一对多充电方案,这是一种允许一个充电...
View Assessment Result: Multiple-Choice Quiz 2 Your performance was as follows: 1. The degree of a table is the number of _____ in the table. (a) keys (b) columns (c) rows (d) ...
may be associated with multiple labels simultaneously. A key difference between multi-label learning and traditional binary or multi-class learning is that the labels in multi-label learning are not ...
### Outlook错误代码详解 #### 一、概述 ...通过理解这些错误的具体含义和背景,用户可以更有效地解决问题。在尝试上述解决方案后,如果问题仍未解决,建议联系技术支持或邮件服务器管理员获取进一步的帮助。
TEmailServer is a built-in SMTP server that can simultaneously validate or verify email addresses and send multiple email messages. This component is ideal for building email address validator or ...
破解版 TEmailServer is a built-in SMTP server that can simultaneously validate or verify email addresses and send multiple email messages. TEmailServer is an ideal component for building email address...
超市闭路电视监控系统解决方案 超市闭路电视监控系统解决方案是一种综合性解决方案,旨在提供一个高效、可靠、实时的监控系统,以满足超市的安全需求。该系统由闭路监控系统、防盗报警系统和主控室配置三部分组成。...
You can communicate with multiple ports simultaneously. See the Quick Start Guide. MBAXP Technical Facts and Features: RTU Mode. ASCII Mode. Modbus TCP/IP. Multi-threaded for high data throughput. ...
or installed on a single workstation used non-simultaneously by multiple people, but not both. You may access the registered version of SVGDeveloper through a network, provided that you have obtained...
If more than 8 analog input channels are required, multiple cards can be synchronized through the Device-to-Device Bus to support more AI channels simultaneously sampling. The PCI-1706U has two 12-...
In order to track multiple particles within a whole cell simultaneously, a parallel tracking approach with large depth of field was put forward. It was based on distorted grating and dual-objective ...