找到对集合 org.hibernate.HibernateException 的共享引用 [英] Found shared references to a collection org.hibernate.HibernateException

查看:23
本文介绍了找到对集合 org.hibernate.HibernateException 的共享引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误消息:

错误:找到对集合的共享引用:Person.relatedPersons

error: Found shared references to a collection: Person.relatedPersons

当我尝试执行 addToRelatedPersons(anotherPerson) 时:

person.addToRelatedPersons(anotherPerson);
anotherPerson.addToRelatedPersons(person);

anotherPerson.save();
person.save();

我的域:

Person {

 static hasMany = [relatedPersons:Person];

}

知道为什么会这样吗?

推荐答案

当您尝试保留多个共享相同集合引用(即集合标识相反的实体实例)时,Hibernate 会显示此错误与集合相等).

Hibernate shows this error when you attempt to persist more than one entity instance sharing the same collection reference (i.e. the collection identity in contrast with collection equality).

请注意,这意味着相同的 collection,而不是集合元素 - 换句话说,personanotherPerson 上的 relatedPersons代码> 必须相同.也许您正在加载实体后重置该集合?或者你已经用同一个集合实例初始化了两个引用?

Note that it means the same collection, not collection element - in other words relatedPersons on both person and anotherPerson must be the same. Perhaps you're resetting that collection after entities are loaded? Or you've initialized both references with the same collection instance?

这篇关于找到对集合 org.hibernate.HibernateException 的共享引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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