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.

Activity

Andrea BorieroJanuary 30, 2023 at 2:36 PM

Thanks !

Christoph WatzlJanuary 30, 2023 at 1:13 PM

@Andrea Boriero

I opened a new issue with a test case:

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?

Thank you very much!

Fixed

Details

Assignee

Reporter

Components

Fix versions

Affects versions

Priority

Created September 15, 2022 at 8:55 AM
Updated July 16, 2024 at 8:59 AM
Resolved September 23, 2022 at 9:46 AM