Hibernate - cascade =“all-delete-orphan”的集合不再被拥有的实体实例引用 [英] Hibernate - A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance

查看:969
本文介绍了Hibernate - cascade =“all-delete-orphan”的集合不再被拥有的实体实例引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 Cascade =collection with cascade =all- delete-orphan不再被拥有实体实例引用。 

我有一个父实体,它有一个 Set< ...> ; 一些儿童实体。当我尝试更新它时,我将所有引用设置为此集合并进行设置。



以下代码代表我的映射:

  @OneToMany(mappedBy =parentEntity,fetch = FetchType.EAGER)
@Cascade({CascadeType。 ALL,CascadeType.DELETE_ORPHAN})
public Set< ChildEntity> getChildren(){
return this.children;
}

我试着只清理Set< ..>,根据这:如何可能解决问题,但无效。



如果您有任何想法,请让我知道。



谢谢!

解决方案

实际上,我的问题是关于我的实体的equals和hashcode。遗留代码会带来很多问题,不要忘记检查它。我所做的只是保持删除孤儿的策略,正确的等号和散列码。


I'm having the following issue when trying to update my entity:

"A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance".

I have a parent entity and it has a Set<...> of some children entities. When I try to update it, I get all the references to be set to this collections and set it.

The following code represents my mapping:

@OneToMany(mappedBy = "parentEntity", fetch = FetchType.EAGER)
@Cascade({ CascadeType.ALL, CascadeType.DELETE_ORPHAN })
public Set<ChildEntity> getChildren() {
    return this.children;
}

I've tried to clean the Set<..> only, according to this: How to "possible" solve the problem but it didn't work.

If you have any ideas, please let me know.

Thanks!

解决方案

Actually, my problem was about equals and hashcode of my entities. A legacy code can bring a lot of problems, never forget to check it out. All I've done was just keep delete-orphan strategy and correct equals and hashcode.

这篇关于Hibernate - cascade =“all-delete-orphan”的集合不再被拥有的实体实例引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆