hibernate4的级联删除为什么不行啊?
我刚刚在做部门模块,结果在部门树形结构下想删除某个节点,一带把他的子节点也删除了,但如何设置都发现删除不了,会报出错误:
- Cannot delete or update a parent row: a foreign key constraint fails (`oa`.`department`, CONSTRAINT `FK_rll3cq4b2ghx2lmgj6c31o70m` FOREIGN KEY (`parentDept_id`) REFERENCES `department` (`id`))
- could not execute statement
- 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都不行,请各位大神求教?