Fixed
Details
Assignee
Yoann RodièreYoann RodièreReporter
Yoann RodièreYoann RodièreComponents
Sprint
NoneFix versions
Priority
Major
Details
Details
Assignee
Yoann Rodière
Yoann RodièreReporter
Yoann Rodière
Yoann RodièreComponents
Sprint
None
Fix versions
Priority
Created September 8, 2020 at 8:58 AM
Updated October 8, 2020 at 12:30 PM
Resolved September 24, 2020 at 12:31 PM
Relevant test in Search 5:
org.hibernate.search.test.embedded.EmbeddedTest#testEmbeddedIndexing
, the very last transaction.If:
An entity
A
is embedded in an entityB
through@IndexedEmbedded
on an associationB.a
Entity
A
has an@ElementCollection
property,A.elementCollection
, which is indexed-embedded in BThe inverse side of
B.a
in entityA
is namedA.b
, and that inverse side is lazy, andA
is not the owner of that association.Entity
A
gets loaded in the session, then deleted immediatelyThen Hibernate Search will:
Receive a
PostCollectionRemove
event and markA
as updated as a resultReceive a deletion event for
A
and mark A for deletion as a resultResolve the entities that should be reindexed as a result of the update of A
Access the association from
A
toB
becauseelementCollection
changed and is embedded inB
LazyInitializationException
is thrownIn Search 5, we used to have this piece of code in
AbstractDocumentBuilder
to guard us against this problem:It does work around the problem, but I'm not sure it is safe. In particular,
B
could be referencing another entity through this association, sayA2
, and that other entity would need to be updated following the deletion ofB
. As far as I can tell, in Search 5A2
will just become out of sync.There are multiple solutions:
We could use the same workaround: give the mapper a chance to attempt the initialization of the collection before we proceed, and to return null if the collection cannot be initialized. For example add an
initializeOrNull()
method toPojoRuntimeIntrospector
. But that means accepting thatA2
becomes out of sync in the example above.We could decide not to resolve reindexing upon deletion. Essentially we'd expect associations referencing the deleted entity to be systematically updated, so reindexing will be triggered because of these updates. This is consistent with what we require for association updates. It would be a shame, though, because in many cases we absolutely can resolve reindexing.
We could try to see if the
LazyInitializationException
being thrown is a bug, and if so fix it in ORM.We could try to detect this problem at bootstrap time and refuse the mapping unless someone adds
@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.NO
. For example if we detect an association where one side is Many and lazy, and the other is owner and has CascadeType.REMOVE. But I doubt we can accurately detect all cases.