Querying for an entity persisted but not flushed to the database causes the exception 'A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance'
Description
I cannot even explain what is happening here, you have to see for yourself. But you need JUnit 5 to run the test case below. The exception hibernate throws is the following:
A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: org.hibernate.bugs.TestHHH15511$EntityHHH15511.absolutelyIrrelevant
But absolutelyIrrelevant is indeed absolutely irrelevant. This collection is never touched in the entire test case.
It looks like something bad is happening, when the persist() of the entities requires an INSERT due to generation strategy IDENTITY. If I remove that, the bug does not occur. If I keep the strategy IDENTITY and add a manual flush() after persist, the bug also does not occur.
Turned out it is a different issue, even though the symptoms are quite similar. It appears to be related to Embeddables.
Christoph WatzlJanuary 30, 2023 at 12:38 PM
Seems like the issue I found isn’t exactly the same after all, just with very similar symptoms. The original reproducer for HHH-15512 is green on 6.2.0.CR2. Investigating.
Christoph WatzlJanuary 30, 2023 at 8:23 AM
Will do, as soon as I find the time, but probably some time today.
Andrea BorieroJanuary 30, 2023 at 8:07 AM
Hi ,
can you please open a new issue and attach a test case?
I cannot even explain what is happening here, you have to see for yourself. But you need JUnit 5 to run the test case below. The exception hibernate throws is the following:
But
absolutelyIrrelevant
is indeed absolutely irrelevant. This collection is never touched in the entire test case.It looks like something bad is happening, when the
persist()
of the entities requires an INSERT due to generation strategy IDENTITY. If I remove that, the bug does not occur. If I keep the strategy IDENTITY and add a manualflush()
after persist, the bug also does not occur.