【发布时间】:2011-08-01 01:02:46
【问题描述】:
我在尝试更新我的实体时遇到以下问题:
"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<..>,根据此:How to "possible" solve the problem 但它不起作用。
如果您有任何想法,请告诉我。
谢谢!
【问题讨论】:
-
@mel3kings,您提供的链接已失效。
-
在移除元素时尝试使用可变集合。例如,如果
manyother是List<T>,则不要使用something.manyother.remove(other)。使许多其他可变的,例如ArrayList<T>并使用orphanDelete = true -
有一个看起来非常相似的错误:hibernate.atlassian.net/browse/HHH-9940 重现它的代码:github.com/abenneke/sandbox/tree/master/…
-
链接“如何“可能”解决问题”不再可用
标签: java hibernate hibernate-mapping