I have following table entities, In that I am trying update an existing record, while doing so i get following error. I know I'm doing some mistake in the entity definition but not able to figure it out. Appreciate your help.
**A
-------------------
| |
B C
---------
| |
D E**
@Entity
@Table()
public class A {
@Id
Long id;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval=true)
@JoinColumn(name = "id", referencedColumnName="id", nullable = false)
private Set<B> b;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval=true)
@JoinColumn(name = "id", referencedColumnName="ID", nullable = false)
private Set<C> c;
}
@Entity
@Table()
public class B{
@Id
Long id;
}
@Entity
@Table()
public class C{
@Id
Long id;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval=true)
@JoinColumn(name = "id", referencedColumnName="id", nullable = false)
private Set<D> D;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval=true)
@JoinColumn(name = "id", referencedColumnName="ID", nullable = false)
private Set<E> E;
}
@Entity
@Table()
public class D{
@Id
Long id;
}
@Entity
@Table()
public class E{
@Id
Long id;
}
ERROR:
org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: com.entity.C.D
at org.hibernate.engine.internal.Collections.processDereferencedCollection(Collections.java:100) ~[hibernate-core-5.3.12.Final.jar:5.3.12.Final]
at org.hibernate.engine.internal.Collections.processUnreachableCollection(Collections.java:51) ~[hibernate-core-5.3.12.Final.jar:5.3.12.Final]
at org.hibernate.event.internal.AbstractFlushingEventListener.flushCollections(AbstractFlushingEventListener.java:262) ~[hibernate-core-5.3.12.Final.jar:5.3.12.Final]
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:95) ~[hibernate-core-5.3.12.Final.jar:5.3.12.Final]