given
{noformat}@Entity(name = "parent") @Table(name = "parent") public static class Parent { @Id private Long id;
@OneToMany(mappedBy = "parent", cascade = { MERGE }, orphanRemoval = true, fetch = FetchType.LAZY) private List<Child> children = new ArrayList<>(); }
@Entity @Table(name = "child") public static class Child {
@Id private Long id;
@ManyToOne(fetch = FetchType.LAZY) private Parent parent;
}{noformat}
the following
{code:java}inTransaction( session -> { Parent parent = new Parent(); parent = session.merge( parent ); Child child = new Child(); child = session.merge( child ); parent.addChild( child ); } );{code}
causes
{code:java}org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: Parent.children{code} |
|