Hibernate中的异常(不要更改对层叠为"all-delete-orphan"的集合的引用) [英] Exception in Hibernate (Don't change the reference to a collection with cascade="all-delete-orphan")
问题描述
我在休眠状态遇到了一个奇怪的问题.我在项目中使用冬眠和春季.
I am getting a weird problem in hibernate. I am using hibernate and spring in my project.
问题是我有一个父子关系,当我尝试更新父关系时,我遇到了异常
Problem is I am having a parent child relation, and when I try to update the parent I am getting the exception
由以下原因引起:org.hibernate.HibernateException:请勿更改对带有cascade ="all-delete-orphan"的集合的引用
Caused by: org.hibernate.HibernateException: Don't change the reference to a collection with cascade="all-delete-orphan"
以下是映射:
父母:
<set name="kittens" fetch="join" lazy="false"
inverse="true" cascade="all-delete-orphan">
<key>
<column name="ID" precision="22" scale="0"
not-null="true" />
</key>
<one-to-many
class="kitten" />
</set>
孩子:
<composite-id name="id" class="kittenId">
<key-property name="kittenId" type="java.lang.Long">
<column name="Kitten_ID" precision="22" scale="0" />
</key-property>
<key-many-to-one name="cat" class="cat">
<column name="ID" precision="22" scale="0" />
</key-many-to-one>
</composite-id>
我在一个论坛中找到并尝试像
I found in a forum and tried changing like
public void setKittens(Set kittens) {
this.kittens.clear();
this.kittens.addAll(kittens);
}
但是现在我要面对
org.hibernate.PropertyAccessException:在小猫的设置器中发生了异常
org.hibernate.PropertyAccessException: Exception occurred inside setter of Kittens
任何帮助将不胜感激.
推荐答案
我遇到了同样的问题.就我而言,问题是,我错误地而不是将update(Entinty e)
称为save(Entity e)
并得到了此错误.
I had same problem. In my case problem was, that I, by mistake, instead of update(Entinty e)
called save(Entity e)
and got this error.
这篇关于Hibernate中的异常(不要更改对层叠为"all-delete-orphan"的集合的引用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!