Hibernate 4.3.5 到 4.0.1 异常 org.hibernate.loader.MultipleBagFetchException

Hibernate 4.3.5 to 4.0.1 Exception org.hibernate.loader.MultipleBagFetchException

我正在努力将应用程序从 Tomcat 8 迁移到 Weblogic 10.3.6。我们正在使用的技术堆栈:

  1. Spring : 4.1.5.RELEASE
  2. 休眠:4.3.5
  3. 数据库:Postgres

在 Tomcat 8 中,应用程序运行良好,但是当我尝试在 Weblogic 10.3.6 上部署时,由于应用程序使用的是 JPA 2.1,所有应用程序都开始失败。在 Weblogic 10.3.6 上,它默认支持 JPA 1,并且有一个 JPA 2 补丁。

现在为了适应我们的应用程序,我试图通过将 Hibernate 4.3.5 降到 4.0.1 来回到 JPA 2.0。

并从代码中删除了 "javax.persistence.Transactional" 和 "CriteriaDelete"。

现在我正在尝试在 Weblogic 中部署代码,我得到 "Out of memory",稍后我会修复它。

后来我尝试在Tomcat8中部署代码,它抛出异常:

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: abc] Unable to build EntityManagerFactory
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)
    at org.springframework.orm.jpa.vendor.SpringHibernateEjbPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateEjbPersistenceProvider.java:51)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)
    ... 21 more
Caused by: org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags
    at org.hibernate.loader.BasicLoader.postInstantiate(BasicLoader.java:93)
    at org.hibernate.loader.entity.EntityLoader.<init>(EntityLoader.java:118)
    at org.hibernate.loader.entity.EntityLoader.<init>(EntityLoader.java:70)
    at org.hibernate.loader.entity.EntityLoader.<init>(EntityLoader.java:53)
    at org.hibernate.loader.entity.BatchingEntityLoader.createBatchingEntityLoader(BatchingEntityLoader.java:131)
    at org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:2323)
    at org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:2346)
    at org.hibernate.persister.entity.AbstractEntityPersister.createLoaders(AbstractEntityPersister.java:3612)
    at org.hibernate.persister.entity.AbstractEntityPersister.postInstantiate(AbstractEntityPersister.java:3598)
    at org.hibernate.persister.entity.SingleTableEntityPersister.postInstantiate(SingleTableEntityPersister.java:1013)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:422)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)
    at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:84)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
    ... 27 more

请注意,在降级 Hibernate 之前,该应用程序运行良好。

我解决了这个问题。这基本上是由于实体 class 中的多个 fetchtype.Eager 造成了问题。您可以在以下位置找到有关修复的完整信息 “http://blog.eyallupu.com/2010/06/hibernate-exception-simultaneously.html