java - 具有多个级别的休眠级联删除
问题描述
可悲的是,我找不到解决当前问题的方法。(如果我错过了什么,请发布链接)
我有一个多层实体结构如下
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=?
有谁知道为什么添加有效但删除抛出异常?
您需要有关代码的更多信息吗?
解决方案
没关系...错误是由损坏的数据引起的...
推荐阅读
- excel - Number 为常数的公式
- php - 生成具有相同数量元素的子数组
- asp-classic - 在项目模板 [ASP] 中使用“如果条件”
- bash - sed:用 1 行或多行的变量替换模式中的单词
- azure - 从 azure 获取通知“Azure SQL DB 数据库是具有高锁定等待的实例”
- swift - 范围崩溃的不可能索引
- java - 如何从 rxjava 中的 Single Observable 获取值?
- python - 如何从无序的字符串中返回有序字符串?
- python - functools 库的示例不可重现
- swift - SwiftUI:ViewBuilder 无法基于数组创建视图集合