hibernate exception (cannot simultaneously fetch multiple bags)

  1. 云栖社区>
  2. 博客>
  3. 正文

hibernate exception (cannot simultaneously fetch multiple bags)

curiousby 2017-12-28 15:07:00 浏览643
展开阅读全文

 

 

 

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.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:348) 
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872) 
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:906) 
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57) 
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)

 

解决:

改变FetchMode为@Fetch(FetchMode.SUBSELECT),即发送另外一条select语句抓取前面查询到的所有实体对象的关联实体

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

捐助开发者 

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(支持支付宝和微信 以及扣扣群),没钱捧个人场,谢谢各位。

 

个人主页http://knight-black-bob.iteye.com/



 
 
 谢谢您的赞助,我会做的更好!

网友评论

登录后评论
0/500
评论
curiousby
+ 关注