org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.jrock.forum.LegacyCar.tires, no session or session was closed

Hibernate JIRA | Bayo Erinle | 6 years ago
  1. 0

    The root element I am indexing LegacyCarPlant has a reference to LegacyCar, which in turn embeds a collection of LegacyTire. When I kick off the indexer, I always get a LazyInitializationException on the collections. (PS: See stack trace at the tail end) If I make them eager, then the issue goes away, but ideally, I don't want to fetch them eagerly. I'll much rather prefer they remain lazily fetched for obvious reasons. The alternative is to crawl through in a loop and index using fullTextSession.index(T), but that is really really slow as I have upwards of 3million records and still growing. I have read the forums and tried all the suggestions I have seen including trying to run it on a single thread like fullTextSession.createIndexer(LegacyCarPlant.class) .batchSizeToLoadObjects(30) .threadsForSubsequentFetching(1) .threadsToLoadObjects(1) to no avail. Also, I have tried with the snapshot of 3.4.0 and the same error exists. If I do make the root element LegacyPlant, then I don't get the error as well. In my situation though, I need to have LegacyCarPlant be the root. The test program is "legacy_index_run.groovy" Stack Trace: 04:34:30 DEBUG SQL.logStatement - select count(*) as y0_ from Z_LEG_CAR_PLANT this_ 04:34:30 INFO SimpleIndexingProgressMonitor.addToTotalCount - Going to reindex 1 entities 04:34:30 DEBUG SQL.logStatement - select this_.CAR_ID as y0_, this_.PLANT_ID as y1_ from Z_LEG_CAR_PLANT this_ 04:34:30 DEBUG SQL.logStatement - select this_.CAR_ID as CAR1_2_1_, this_.PLANT_ID as PLANT2_2_1_, this_.PLANT_NAME as PLANT3_2_1_, legacycar2_.CAR_ID as CAR1_0_0_, legacycar2_.MODEL as MODEL0_0_ from Z_LEG_CAR_PLANT this_ left outer join Z_LEG_CAR legacycar2_ on this_.CAR_ID=legacycar2_.CAR_ID where (this_.CAR_ID, this_.PLANT_ID) in ((?, ?)) 04:34:30 ERROR LazyInitializationException.<init> - failed to lazily initialize a collection of role: com.jrock.forum.LegacyCar.tires, no session or session was closed org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.jrock.forum.LegacyCar.tires, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:383) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:375) at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:368) at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:111) at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:186) at org.hibernate.search.engine.DocumentBuilderIndexedEntity.buildDocumentFields(DocumentBuilderIndexedEntity.java:457) at org.hibernate.search.engine.DocumentBuilderIndexedEntity.buildDocumentFields(DocumentBuilderIndexedEntity.java:481) at org.hibernate.search.engine.DocumentBuilderIndexedEntity.getDocument(DocumentBuilderIndexedEntity.java:379) at org.hibernate.search.engine.DocumentBuilderIndexedEntity.createAddWork(DocumentBuilderIndexedEntity.java:317) at org.hibernate.search.batchindexing.EntityConsumerLuceneworkProducer.index(EntityConsumerLuceneworkProducer.java:155) at org.hibernate.search.batchindexing.EntityConsumerLuceneworkProducer.indexAllQueue(EntityConsumerLuceneworkProducer.java:123) at org.hibernate.search.batchindexing.EntityConsumerLuceneworkProducer.run(EntityConsumerLuceneworkProducer.java:96) at org.hibernate.search.batchindexing.OptionallyWrapInJTATransaction.run(OptionallyWrapInJTATransaction.java:107) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:680) 04:34:30 ERROR EntityConsumerLuceneworkProducer.run - error during batch indexing: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.jrock.forum.LegacyCar.tires, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:383) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:375) at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:368) at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:111) at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:186) at org.hibernate.search.engine.DocumentBuilderIndexedEntity.buildDocumentFields(DocumentBuilderIndexedEntity.java:457) at org.hibernate.search.engine.DocumentBuilderIndexedEntity.buildDocumentFields(DocumentBuilderIndexedEntity.java:481) at org.hibernate.search.engine.DocumentBuilderIndexedEntity.getDocument(DocumentBuilderIndexedEntity.java:379) at org.hibernate.search.engine.DocumentBuilderIndexedEntity.createAddWork(DocumentBuilderIndexedEntity.java:317) at org.hibernate.search.batchindexing.EntityConsumerLuceneworkProducer.index(EntityConsumerLuceneworkProducer.java:155) at org.hibernate.search.batchindexing.EntityConsumerLuceneworkProducer.indexAllQueue(EntityConsumerLuceneworkProducer.java:123) at org.hibernate.search.batchindexing.EntityConsumerLuceneworkProducer.run(EntityConsumerLuceneworkProducer.java:96) at org.hibernate.search.batchindexing.OptionallyWrapInJTATransaction.run(OptionallyWrapInJTATransaction.java:107) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:680) 04:34:30 INFO SimpleIndexingProgressMonitor.indexingCompleted - Reindexed 1 entities done indexing! Total time taken: 893 ms

    Hibernate JIRA | 6 years ago | Bayo Erinle
    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.jrock.forum.LegacyCar.tires, no session or session was closed
  2. 0

    The root element I am indexing LegacyCarPlant has a reference to LegacyCar, which in turn embeds a collection of LegacyTire. When I kick off the indexer, I always get a LazyInitializationException on the collections. (PS: See stack trace at the tail end) If I make them eager, then the issue goes away, but ideally, I don't want to fetch them eagerly. I'll much rather prefer they remain lazily fetched for obvious reasons. The alternative is to crawl through in a loop and index using fullTextSession.index(T), but that is really really slow as I have upwards of 3million records and still growing. I have read the forums and tried all the suggestions I have seen including trying to run it on a single thread like fullTextSession.createIndexer(LegacyCarPlant.class) .batchSizeToLoadObjects(30) .threadsForSubsequentFetching(1) .threadsToLoadObjects(1) to no avail. Also, I have tried with the snapshot of 3.4.0 and the same error exists. If I do make the root element LegacyPlant, then I don't get the error as well. In my situation though, I need to have LegacyCarPlant be the root. The test program is "legacy_index_run.groovy" Stack Trace: 04:34:30 DEBUG SQL.logStatement - select count(*) as y0_ from Z_LEG_CAR_PLANT this_ 04:34:30 INFO SimpleIndexingProgressMonitor.addToTotalCount - Going to reindex 1 entities 04:34:30 DEBUG SQL.logStatement - select this_.CAR_ID as y0_, this_.PLANT_ID as y1_ from Z_LEG_CAR_PLANT this_ 04:34:30 DEBUG SQL.logStatement - select this_.CAR_ID as CAR1_2_1_, this_.PLANT_ID as PLANT2_2_1_, this_.PLANT_NAME as PLANT3_2_1_, legacycar2_.CAR_ID as CAR1_0_0_, legacycar2_.MODEL as MODEL0_0_ from Z_LEG_CAR_PLANT this_ left outer join Z_LEG_CAR legacycar2_ on this_.CAR_ID=legacycar2_.CAR_ID where (this_.CAR_ID, this_.PLANT_ID) in ((?, ?)) 04:34:30 ERROR LazyInitializationException.<init> - failed to lazily initialize a collection of role: com.jrock.forum.LegacyCar.tires, no session or session was closed org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.jrock.forum.LegacyCar.tires, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:383) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:375) at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:368) at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:111) at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:186) at org.hibernate.search.engine.DocumentBuilderIndexedEntity.buildDocumentFields(DocumentBuilderIndexedEntity.java:457) at org.hibernate.search.engine.DocumentBuilderIndexedEntity.buildDocumentFields(DocumentBuilderIndexedEntity.java:481) at org.hibernate.search.engine.DocumentBuilderIndexedEntity.getDocument(DocumentBuilderIndexedEntity.java:379) at org.hibernate.search.engine.DocumentBuilderIndexedEntity.createAddWork(DocumentBuilderIndexedEntity.java:317) at org.hibernate.search.batchindexing.EntityConsumerLuceneworkProducer.index(EntityConsumerLuceneworkProducer.java:155) at org.hibernate.search.batchindexing.EntityConsumerLuceneworkProducer.indexAllQueue(EntityConsumerLuceneworkProducer.java:123) at org.hibernate.search.batchindexing.EntityConsumerLuceneworkProducer.run(EntityConsumerLuceneworkProducer.java:96) at org.hibernate.search.batchindexing.OptionallyWrapInJTATransaction.run(OptionallyWrapInJTATransaction.java:107) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:680) 04:34:30 ERROR EntityConsumerLuceneworkProducer.run - error during batch indexing: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.jrock.forum.LegacyCar.tires, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:383) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:375) at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:368) at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:111) at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:186) at org.hibernate.search.engine.DocumentBuilderIndexedEntity.buildDocumentFields(DocumentBuilderIndexedEntity.java:457) at org.hibernate.search.engine.DocumentBuilderIndexedEntity.buildDocumentFields(DocumentBuilderIndexedEntity.java:481) at org.hibernate.search.engine.DocumentBuilderIndexedEntity.getDocument(DocumentBuilderIndexedEntity.java:379) at org.hibernate.search.engine.DocumentBuilderIndexedEntity.createAddWork(DocumentBuilderIndexedEntity.java:317) at org.hibernate.search.batchindexing.EntityConsumerLuceneworkProducer.index(EntityConsumerLuceneworkProducer.java:155) at org.hibernate.search.batchindexing.EntityConsumerLuceneworkProducer.indexAllQueue(EntityConsumerLuceneworkProducer.java:123) at org.hibernate.search.batchindexing.EntityConsumerLuceneworkProducer.run(EntityConsumerLuceneworkProducer.java:96) at org.hibernate.search.batchindexing.OptionallyWrapInJTATransaction.run(OptionallyWrapInJTATransaction.java:107) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:680) 04:34:30 INFO SimpleIndexingProgressMonitor.indexingCompleted - Reindexed 1 entities done indexing! Total time taken: 893 ms

    Hibernate JIRA | 6 years ago | Bayo Erinle
    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.jrock.forum.LegacyCar.tires, no session or session was closed
  3. 0

    Hibernate LazyInitializationException thrown when called through Restful web service

    Stack Overflow | 3 years ago | KaR
    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.spaneos.ias.pojo.Question.answers, no session or session was closed
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Error Hibernate propperty "Lazy"

    Stack Overflow | 3 years ago | Victor Elizondo
    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: org.citi.tablero.contraloria.planes.model.db.hibernate.dto.SigTcContraloriaObjetivos.children, no session or session was closed
  6. 0

    hibernate LazyInitializing paradox

    Stack Overflow | 4 years ago | Ehsan
    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: Discipline.managements, no session or session was closed

    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.jrock.forum.LegacyCar.tires, no session or session was closed

      at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException()
    2. Hibernate
      PersistentSet.iterator
      1. org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:383)
      2. org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:375)
      3. org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:368)
      4. org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:111)
      5. org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:186)
      5 frames
    3. Hibernate Search Engine
      OptionallyWrapInJTATransaction.run
      1. org.hibernate.search.engine.DocumentBuilderIndexedEntity.buildDocumentFields(DocumentBuilderIndexedEntity.java:457)
      2. org.hibernate.search.engine.DocumentBuilderIndexedEntity.buildDocumentFields(DocumentBuilderIndexedEntity.java:481)
      3. org.hibernate.search.engine.DocumentBuilderIndexedEntity.getDocument(DocumentBuilderIndexedEntity.java:379)
      4. org.hibernate.search.engine.DocumentBuilderIndexedEntity.createAddWork(DocumentBuilderIndexedEntity.java:317)
      5. org.hibernate.search.batchindexing.EntityConsumerLuceneworkProducer.index(EntityConsumerLuceneworkProducer.java:155)
      6. org.hibernate.search.batchindexing.EntityConsumerLuceneworkProducer.indexAllQueue(EntityConsumerLuceneworkProducer.java:123)
      7. org.hibernate.search.batchindexing.EntityConsumerLuceneworkProducer.run(EntityConsumerLuceneworkProducer.java:96)
      8. org.hibernate.search.batchindexing.OptionallyWrapInJTATransaction.run(OptionallyWrapInJTATransaction.java:107)
      8 frames
    4. Java RT
      Thread.run
      1. java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      2. java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      3. java.lang.Thread.run(Thread.java:680)
      3 frames