我在尝试更新实体时遇到以下问题:
"A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance".
我有一个父实体,它拥有一组某些子实体的Set<...>
。当我尝试更新它时,我将所有引用设置为该集合并进行设置。
下面的代码表示我的映射:
@OneToMany(mappedBy = "parentEntity", fetch = FetchType.EAGER)
@Cascade({ CascadeType.ALL, CascadeType.DELETE_ORPHAN })
public Set<ChildEntity> getChildren() {
return this.children;
}
我尝试根据这个链接:如何“可能”解决问题,仅清理Set<..>,但它没有起作用。
如果您有任何想法,请告诉我。
谢谢!
manyother
是一个List<T>
,不要使用something.manyother.remove(other)
。将manyother
变为可变的,如ArrayList<T>
,并使用orphanDelete = true
。 - nurettin