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

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

  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都不行,请各位大神求教?

hibernate4的级联删除为什么不行啊?,布布扣,bubuko.com

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

上一篇:linux系统调用和库函数调用的区别(转)


下一篇:用C#写个小程序爬取漫画