2017-08-08 28 views
0

我有两个表,这些类:@OneToMany删除不活像

全球史:

@ManyToOne 
@JoinColumn(name = "ID_HISTORY", nullable = true) 
private History history; 

历史一个简单的类。

我想undrestand为什么当我尝试删除全球历史我得到这个错误:

org.hibernate.exception.ConstraintViolationException:不能删除或更新父行:外键约束失败

回答

0

看起来好像你想要DELETE你的表中有一些记录在Parent-Child relationship。 检查您是否有Parent-Child relationship中的表格。这就像当你有一张桌子Department(假设为Parent table,这里你有所有部门唯一ID)和Employees表(假设为Child table(外键),这里你有Department表中雇员所属的department_id keys) 。当你想要Update OR DeleteParent table并且没有referential actions时,那么数据库保护Child's table来自这些操作的数据;

您也可以在这里阅读:https://www.w3schools.com/sql/sql_foreignkey.asp