具有多个级别的休眠级联删除
hibernate cascading delete with multiple levels
很遗憾,我找不到解决当前问题的方法。 (如果我遗漏了什么,请post一个link)
我有一个多层实体结构如下
class Parent {
@OneToMany(
mappedBy = "parent",
cascade = CascadeType.ALL,
orphanRemoval = true
)
private Set<ChildA> setOfChildA = new HashSet<>();
@OneToMany( fetch = FetchType.EAGER, mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true )
private Set<ChildB> setOfChildB = new HashSet<>();
}
class ChildB {
@OneToMany( fetch = FetchType.LAZY, mappedBy = "childb", cascade = CascadeType.ALL, orphanRemoval = true )
private Set<grandchild> grandchild = new HashSet<>();
}
当我添加 Parent.setOfChildA
和添加 ChildB.grandchild
并且只保存父实体时,一切正常。
但是当我删除 Parent.setOfChildA
和删除一些 ChildB.grandchild
时,我得到以下异常
.m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.orm.jpa.JpaSystemException: Batch update returned unexpected row count from update [0]; actual row count: 2; expected: 1; nested exception is org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 2; expected: 1]
Hibernate 记录以下 sql 语句
delete
from
tbl_childa
where
childa_linkparentid=?
and childa_linkotherentityid=?
delete
from
tbl_grandchild
where
grandchild_id=?
and grandchild_version=?
有谁知道为什么添加有效但删除会抛出异常?
您需要有关代码的更多信息吗?
没关系...错误是由损坏的数据引起的...
很遗憾,我找不到解决当前问题的方法。 (如果我遗漏了什么,请post一个link)
我有一个多层实体结构如下
class Parent {
@OneToMany(
mappedBy = "parent",
cascade = CascadeType.ALL,
orphanRemoval = true
)
private Set<ChildA> setOfChildA = new HashSet<>();
@OneToMany( fetch = FetchType.EAGER, mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true )
private Set<ChildB> setOfChildB = new HashSet<>();
}
class ChildB {
@OneToMany( fetch = FetchType.LAZY, mappedBy = "childb", cascade = CascadeType.ALL, orphanRemoval = true )
private Set<grandchild> grandchild = new HashSet<>();
}
当我添加 Parent.setOfChildA
和添加 ChildB.grandchild
并且只保存父实体时,一切正常。
但是当我删除 Parent.setOfChildA
和删除一些 ChildB.grandchild
时,我得到以下异常
.m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.orm.jpa.JpaSystemException: Batch update returned unexpected row count from update [0]; actual row count: 2; expected: 1; nested exception is org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 2; expected: 1]
Hibernate 记录以下 sql 语句
delete
from
tbl_childa
where
childa_linkparentid=?
and childa_linkotherentityid=?
delete
from
tbl_grandchild
where
grandchild_id=?
and grandchild_version=?
有谁知道为什么添加有效但删除会抛出异常?
您需要有关代码的更多信息吗?
没关系...错误是由损坏的数据引起的...