【发布时间】:2020-05-28 21:01:58
【问题描述】:
我有以下表格实体,因为我正在尝试更新现有记录,但这样做时出现以下错误。我知道我在实体定义中犯了一些错误,但无法弄清楚。 感谢您的帮助。
**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;
}
错误:
org.hibernate.HibernateException:拥有的实体实例不再引用具有 cascade="all-delete-orphan" 的集合: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]
【问题讨论】:
标签: java hibernate spring-boot spring-data-jpa hibernate-5.x