When persisting ant entity *Parent* with a collection *children,* mapped as *all-delete-orphan,* set to null and then loading the same entity in a query results in:
org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: org.hibernate.bugs.domain.Parent.children
Sample code:
{code:java}@Entity public class Parent { @Id @GeneratedValue private Long id;
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true) private List<Child> children; } {code}
{code:java}@Entity public class Child { @Id @GeneratedValue private Long id;
@ManyToOne private Parent parent; } {code}
Persisting and querying:
{code:java} var p = new Parent(); entityManager.persist(p);
for (var parent : entityManager.createQuery("from Parent", Parent.class).getResultList()) { System.out.println(parent.getChildren()); }{code}
Test case attached. |
|