I came across this strange bug while implementing lazy loading using Bytecode enhancement in our application. At some point in our code, we do the following operations in a single session:
(obviously very simplified)
With relevant Entities:
The Code works fine with bytecode enhancement in Version 5.2.12. In higher Versions of Hibernate the code fails on the second flush with an Exception:
org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: hibernate.model.SubItem.superAssociation
If we turn off bytecode enhancement, it works fine in all the versions I have tried.
See the attached Test Case for the concrete example.
java version: 1.8.0_92
maven version: 3.6.1
OS: Windows 10
DB: Derby (10.12.1.1), Oracle DB 19c