postgresql约束违规异常

时间:2018-05-15 15:28:25

标签: postgresql spring-data-jpa

Class A {
private String name;
}

Class B {
@OneToOne(orphanRemoval = true)
@NotNull
@JoinColumn(name = "a")
private A a;
}

A-B是一对一的关系。 当我打电话

b.getA().setName("fake");
aDao.save(b.getA());
bDao.delete(b);

我得到"error": "could not execute statement; SQL [n/a]; constraint [b_a_fkey]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement"

但我没有在A类上设置cascade.delete,为什么bDao.delete(b)会抛出错误?

感谢。

0 个答案:

没有答案