LazyInitializationException while indexing in Hibernate Search MassIndexer

Solution Unverified - Updated -

Environment

  • JBoss Web Framework Kit

    • 2.5.0

Issue

On implementing a custom bridge, that collects all fields of associated classes, that are named "ALL". The goal is, to create an all-field, that spans the parent-class and all its associated classes.

The custom bridge works fine for all "normal" fields of the parent class and the first associated class.

But if the associated class contains another associated class, a LazyInitializationException is raised, when indexing with MassIndexer.startAndWait():


HSEARCH000116: Unexpected error during MassIndexer operation org.hibernate.search.bridge.BridgeException: Exception while calling bridge#set class: com.test.b.Foo path: bar at org.hibernate.search.bridge.util.impl.ContextualExceptionBridgeHelper.buildBridgeException(ContextualExceptionBridgeHelper.java:97) at org.hibernate.search.bridge.util.impl.ContextualExceptionBridgeHelper$OneWayConversionContextImpl.set(ContextualExceptionBridgeHelper.java:126) at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.buildDocumentFields(DocumentBuilderIndexedEntity.java:533) at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.getDocument(DocumentBuilderIndexedEntity.java:478) at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.createAddWork(DocumentBuilderIndexedEntity.java:401) at org.hibernate.search.batchindexing.impl.EntityConsumerLuceneWorkProducer.index(EntityConsumerLuceneWorkProducer.java:172) at org.hibernate.search.batchindexing.impl.EntityConsumerLuceneWorkProducer.indexAllQueue(EntityConsumerLuceneWorkProducer.java:132) at org.hibernate.search.batchindexing.impl.EntityConsumerLuceneWorkProducer.run(EntityConsumerLuceneWorkProducer.java:102) at org.hibernate.search.batchindexing.impl.OptionallyWrapInJTATransaction.run(OptionallyWrapInJTATransaction.java:112) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:679) Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.test.b.Bar.foobars, no session or session was closed at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:393) at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:385) at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:378) at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:112) at org.hibernate.collection.internal.PersistentSet.toString(PersistentSet.java:326) at com.AllBridge.handleField(AllBridge.java:185) at com.AllBridge.recursion(AllBridge.java:106) at com.AllBridge.set(AllBridge.java:65) at org.hibernate.search.bridge.util.impl.ContextualExceptionBridgeHelper$OneWayConversionContextImpl.set(ContextualExceptionBridgeHelper.java:123)

The Exception might also be thrown, when indexing an not fully initalized entity asynchronously.

Resolution

This issue is fixed in hibernate Search version 4.4.3 . This Hibernate Search version is available in WFK 2.6. you cab download it form here.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments