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

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

问题描述

我在尝试更新我的实体时遇到以下问题:

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".

我有一个父实体,它有一些子实体的 Set<...>.当我尝试更新它时,我获得了要设置到此集合的所有引用并进行设置.

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;
}

我尝试只清理 Set<..>,根据这个:如何可能"解决问题 但它没有用.

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.

谢谢!

推荐答案

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

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 - 拥有级联=“all-delete-orphan"的集合不再被拥有的实体实例引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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