如何删除从其他对象引用的对象?例子:
Person person = new Person();
Payment payment = new Payment();
payment.setReceiverOfPayment(person);
dao.delete(person);
课程:
class Person {
}
class Payment {
//optional
@OneToOne
private Person receiverOfPayment;
}
现在,如果我删除对象 person,我会遇到异常:
org.hsqldb.HsqlException: integrity constraint violation: foreign key no action;
FK_PAYMENT_RECEIVEROFPAYMENT_ID table: PAYMENT
这当然是因为某些付款可能仍然与人有关。
在我删除一个人并手动清除引用之前,我是否必须在数据库中迭代我的所有付款?或者是否有任何可以自动处理的级联(或类似)选项?