org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.test.hibernate.ChildEntity.parents, no session or session was closed

Spring JIRA | Siarhei Sakovich | 6 years ago
  1. 0

    Hibernate search indexing work fails when it try to load lazy @ContainedIn entity collection. Cause: hibernate session is closed during beforeCompletion: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.test.hibernate.ChildEntity.parents, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:380) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:372) at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:119) at org.hibernate.collection.PersistentSet.size(PersistentSet.java:162) at org.hibernate.search.engine.DocumentBuilderContainedEntity.processContainedInInstances(DocumentBuilderContainedEntity.java:644) at org.hibernate.search.engine.DocumentBuilderContainedEntity.addWorkToQueue(DocumentBuilderContainedEntity.java:612) at org.hibernate.search.backend.impl.BatchedQueueingProcessor.addWorkToBuilderQueue(BatchedQueueingProcessor.java:270) at org.hibernate.search.backend.impl.BatchedQueueingProcessor.processWorkByLayer(BatchedQueueingProcessor.java:248) at org.hibernate.search.backend.impl.BatchedQueueingProcessor.prepareWorks(BatchedQueueingProcessor.java:147) at org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization.beforeCompletion(PostTransactionWorkQueueSynchronization.java:70) at org.hibernate.search.backend.impl.EventSourceTransactionContext$DelegateToSynchronizationOnBeforeTx.doBeforeTransactionCompletion(EventSourceTransactionContext.java:144) at org.hibernate.engine.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:530) at org.hibernate.engine.ActionQueue.beforeTransactionCompletion(ActionQueue.java:211) at org.hibernate.impl.SessionImpl.beforeTransactionCompletion(SessionImpl.java:563) at org.hibernate.jdbc.JDBCContext.beforeTransactionCompletion(JDBCContext.java:229) at org.hibernate.transaction.CacheSynchronization.beforeCompletion(CacheSynchronization.java:96) at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:101) at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:271) at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:89) at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:176) at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1396) at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:138) at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1009) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:374) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621) at com.test.hibernate.TestService$$EnhancerByCGLIB$$f6772efb.update(<generated>) at com.test.hibernate.TestHb.testHb(TestHb.java:26) Configuration: Spring context: <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> ... <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> ..<property name="hibernateProperties"> <props> <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</prop> <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>.. <tx:annotation-driven transaction-manager="transactionManager" /> <bean id="jbossTransactionManager" class="com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple"/> <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManager" ref="jbossTransactionManager" /> </bean> jndi.properties: java.naming.factory.initial = org.apache.xbean.spring.jndi.SpringInitialContextFactory jndi.xml: <bean id="jndi" class="org.apache.xbean.spring.jndi.SpringInitialContextFactory" factory-method="makeInitialContext"> <property name="entries"> <map> <entry key="java:/TransactionManager"> <bean class="com.arjuna.ats.jta.TransactionManager" factory-method="transactionManager"> </bean> </entry> <entry key="UserTransaction"> <bean class="com.arjuna.ats.jta.UserTransaction" factory-method="userTransaction"> </bean> </entry> </map> </property> </bean> Full eclipse test project is attached

    Spring JIRA | 6 years ago | Siarhei Sakovich
    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.test.hibernate.ChildEntity.parents, no session or session was closed
  2. 0

    Hibernate search indexing work fails when it try to load lazy @ContainedIn entity collection. Cause: hibernate session is closed during beforeCompletion: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.test.hibernate.ChildEntity.parents, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:380) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:372) at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:119) at org.hibernate.collection.PersistentSet.size(PersistentSet.java:162) at org.hibernate.search.engine.DocumentBuilderContainedEntity.processContainedInInstances(DocumentBuilderContainedEntity.java:644) at org.hibernate.search.engine.DocumentBuilderContainedEntity.addWorkToQueue(DocumentBuilderContainedEntity.java:612) at org.hibernate.search.backend.impl.BatchedQueueingProcessor.addWorkToBuilderQueue(BatchedQueueingProcessor.java:270) at org.hibernate.search.backend.impl.BatchedQueueingProcessor.processWorkByLayer(BatchedQueueingProcessor.java:248) at org.hibernate.search.backend.impl.BatchedQueueingProcessor.prepareWorks(BatchedQueueingProcessor.java:147) at org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization.beforeCompletion(PostTransactionWorkQueueSynchronization.java:70) at org.hibernate.search.backend.impl.EventSourceTransactionContext$DelegateToSynchronizationOnBeforeTx.doBeforeTransactionCompletion(EventSourceTransactionContext.java:144) at org.hibernate.engine.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:530) at org.hibernate.engine.ActionQueue.beforeTransactionCompletion(ActionQueue.java:211) at org.hibernate.impl.SessionImpl.beforeTransactionCompletion(SessionImpl.java:563) at org.hibernate.jdbc.JDBCContext.beforeTransactionCompletion(JDBCContext.java:229) at org.hibernate.transaction.CacheSynchronization.beforeCompletion(CacheSynchronization.java:96) at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:101) at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:271) at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:89) at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:176) at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1396) at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:138) at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1009) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:374) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621) at com.test.hibernate.TestService$$EnhancerByCGLIB$$f6772efb.update(<generated>) at com.test.hibernate.TestHb.testHb(TestHb.java:26) Configuration: Spring context: <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> ... <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> ..<property name="hibernateProperties"> <props> <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</prop> <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>.. <tx:annotation-driven transaction-manager="transactionManager" /> <bean id="jbossTransactionManager" class="com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple"/> <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManager" ref="jbossTransactionManager" /> </bean> jndi.properties: java.naming.factory.initial = org.apache.xbean.spring.jndi.SpringInitialContextFactory jndi.xml: <bean id="jndi" class="org.apache.xbean.spring.jndi.SpringInitialContextFactory" factory-method="makeInitialContext"> <property name="entries"> <map> <entry key="java:/TransactionManager"> <bean class="com.arjuna.ats.jta.TransactionManager" factory-method="transactionManager"> </bean> </entry> <entry key="UserTransaction"> <bean class="com.arjuna.ats.jta.UserTransaction" factory-method="userTransaction"> </bean> </entry> </map> </property> </bean> Full eclipse test project is attached

    Spring JIRA | 6 years ago | Siarhei Sakovich
    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.test.hibernate.ChildEntity.parents, no session or session was closed
  3. 0

    Spring3/Hibernate3/TestNG: some tests give LazyInitializationException, some don't

    Stack Overflow | 7 years ago | niklassaers
    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: tld.mydomain.sample.entities.User.roles, no session or session was closed
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    [memcached-session-manager] Session Failover with Groovy on Grails Applications

    Google Groups | 7 years ago | Johannes
    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: Person.depotPositions, no session or session was closed
  6. 0

    hibernate延迟加载的错误 failed to lazily initialize a collection of role - 冰是睡着的水的日志 - 网易博客

    163.com | 8 months ago
    org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed

  1. treefolk 2 times, last 2 weeks ago
  2. mortalman7 1 times, last 4 months ago
1 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. org.hibernate.LazyInitializationException

    failed to lazily initialize a collection of role: com.test.hibernate.ChildEntity.parents, no session or session was closed

    at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException()
  2. Hibernate
    PersistentSet.size
    1. org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:380)
    2. org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:372)
    3. org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:119)
    4. org.hibernate.collection.PersistentSet.size(PersistentSet.java:162)
    4 frames
  3. Hibernate Search Engine
    EventSourceTransactionContext$DelegateToSynchronizationOnBeforeTx.doBeforeTransactionCompletion
    1. org.hibernate.search.engine.DocumentBuilderContainedEntity.processContainedInInstances(DocumentBuilderContainedEntity.java:644)
    2. org.hibernate.search.engine.DocumentBuilderContainedEntity.addWorkToQueue(DocumentBuilderContainedEntity.java:612)
    3. org.hibernate.search.backend.impl.BatchedQueueingProcessor.addWorkToBuilderQueue(BatchedQueueingProcessor.java:270)
    4. org.hibernate.search.backend.impl.BatchedQueueingProcessor.processWorkByLayer(BatchedQueueingProcessor.java:248)
    5. org.hibernate.search.backend.impl.BatchedQueueingProcessor.prepareWorks(BatchedQueueingProcessor.java:147)
    6. org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization.beforeCompletion(PostTransactionWorkQueueSynchronization.java:70)
    7. org.hibernate.search.backend.impl.EventSourceTransactionContext$DelegateToSynchronizationOnBeforeTx.doBeforeTransactionCompletion(EventSourceTransactionContext.java:144)
    7 frames
  4. Hibernate
    ActionQueue.beforeTransactionCompletion
    1. org.hibernate.engine.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:530)
    2. org.hibernate.engine.ActionQueue.beforeTransactionCompletion(ActionQueue.java:211)
    2 frames
  5. Hibernate
    SessionImpl.beforeTransactionCompletion
    1. org.hibernate.impl.SessionImpl.beforeTransactionCompletion(SessionImpl.java:563)
    1 frame
  6. Hibernate
    CacheSynchronization.beforeCompletion
    1. org.hibernate.jdbc.JDBCContext.beforeTransactionCompletion(JDBCContext.java:229)
    2. org.hibernate.transaction.CacheSynchronization.beforeCompletion(CacheSynchronization.java:96)
    2 frames
  7. JBossTS jbossjta
    BaseTransaction.commit
    1. com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:101)
    2. com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:271)
    3. com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:89)
    4. com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:176)
    5. com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1396)
    6. com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:138)
    6 frames
  8. Spring Tx
    TransactionInterceptor.invoke
    1. org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1009)
    2. org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
    3. org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
    4. org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:374)
    5. org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
    5 frames
  9. Spring AOP
    Cglib2AopProxy$DynamicAdvisedInterceptor.intercept
    1. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    2. org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621)
    2 frames
  10. com.test.hibernate
    TestHb.testHb
    1. com.test.hibernate.TestService$$EnhancerByCGLIB$$f6772efb.update(<generated>)
    2. com.test.hibernate.TestHb.testHb(TestHb.java:26)
    2 frames