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

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

问题描述


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


当我试图执行 addToRelatedPersons(anotherPerson)

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

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

我的网域:

  Person {

static hasMany = [relatedPersons:Person];

}

任何想法为何发生这种情况?

解决方案

当您试图持续共享相同集合引用的多个实体实例时(例如集合标识与收集相等)。



请注意,它表示相同的集合,而不是集合元素 - 换句话说关于 person anotherPerson 的relatedPersons 必须相同。也许你正在加载实体后重置该集合?或者你已经用相同的集合实例初始化了两个引用?


I got this error message:

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

When I tried to execute addToRelatedPersons(anotherPerson):

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

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

My domain:

Person {

 static hasMany = [relatedPersons:Person];

}

any idea why this happens ?

解决方案

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

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天全站免登陆