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. TODO: insert test case once the ticket number is generated. |