相关疑难解决方法(0)

不要使用cascade ="all-delete-orphan"更改对集合的引用

我收到一个错误:

不要使用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();
Run Code Online (Sandbox Code Playgroud)

父母和孩子通过one-to-manycascade =' 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>
Run Code Online (Sandbox Code Playgroud)

知道为什么会抛出这个异常吗?为什么即使实体处于分离状态,在主键上设置null也会导致此异常?

java hibernate hibernate-onetomany

8
推荐指数
1
解决办法
2万
查看次数

标签 统计

hibernate ×1

hibernate-onetomany ×1

java ×1