找到对集合org.hibernate.HibernateException的共享引用 [英] Found shared references to a collection 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屋!