很遗憾,我找不到解决当前问题的方法。(如果我错过了什么,请发布链接(
我有一个多层实体结构,如下
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实体时,一切都很好。
但当我删除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=?
有人知道为什么添加是有效的,而删除会引发异常吗?
你需要更多关于代码的信息吗?
永不终止。。。错误是由损坏的数据引起的。。。