我有下面的表实体,因为我试图更新一个现有的记录,这样做我会得到以下错误。我知道我在实体定义中犯了一些错误,但是我无法理解它。谢谢你的帮助。
**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:拥有的实体示例com.entity.c.d不再引用cascade=“all delete orphan”的集合
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]
1条答案
按热度按时间jaql4c8m1#
Map取决于关联的所有权,考虑到您的示例,很难指出,但是您可以查看本文,以便更好地了解在使用一种或另一种方法时在数据库中的后果。我不知道你的更新是否是这样,但是当你更新childs时,你需要清除你过去的集合,并使用addall方法来避免这种错误。也看看这个帖子。