【发布时间】:2013-09-25 11:31:17
【问题描述】:
我收到一个错误:
不要使用 cascade="all-delete-orphan" 更改对集合的引用
同时尝试以下操作:
beginTx();
Parent parent = new Parent();
Child child = new Child();
parent.addChild(child);
getSession().save(parent);
commitTx();
closeSession();
beginTx();
//id is the primary key
child.setID(null);
getSession().update(child);
commitTx();
closeSession();
父母和孩子通过one-to-many 关联,cascade = 'all-delete-orphan'。
class Parent {
Set child;
}
<set name="child" table="Child" cascade="all-delete-orphan" inverse="true">
<key column="FK"></key>
<one-to-many class="Child"/>
</set>
知道为什么会抛出这个异常吗? 为什么即使实体处于分离状态,在主键上设置 null 也会导致此异常?
【问题讨论】:
-
它是针对哪个语句抛出的?是在
child.setID(null);这一行吗? -
childCategory是什么?你想通过调用child.setID(null);来达到什么目的? -
@debojit :它的发生是因为 child.setID(null)
-
@user2599052,通过调用
child.setID(null);,您是否试图删除子集中的特定条目?
标签: java hibernate hibernate-onetomany