hibernate4的级联删除为什么不行啊?

本文探讨了在使用Hibernate框架进行数据库操作时遇到的问题,即在尝试删除部门树形结构中的某节点及其子节点时出现外键约束失败的情况。作者详细描述了问题现象,并提供了实体类中关于级联操作的具体配置。

我刚刚在做部门模块,结果在部门树形结构下想删除某个节点,一带把他的子节点也删除了,但如何设置都发现删除不了,会报出错误:

  1. Cannot delete or update a parent row: a foreign key constraint fails (`oa`.`department`, CONSTRAINT `FK_rll3cq4b2ghx2lmgj6c31o70m` FOREIGN KEY (`parentDept_id`) REFERENCES `department` (`id`))
  2. could not execute statement
  3. could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement

 

我在实体上设置了级联操作了:

@OneToMany(mappedBy="parentDept",cascade=CascadeType.REMOVE,fetch=FetchType.EAGER)
public Set<Department> getChildDepts() {
return childDepts;
}

不管我设置的是ALL还是REMOVE都不行,请各位大神求教?

转载于:https://www.cnblogs.com/yhiloon/p/3656458.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值