我有如下实体,
@Entity
@Table(name = "BENEFICIARY")
public class Beneficiary {
//other fields from entity
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "BENEFICIARY_BANK_ID", nullable = false)
private Bank beneficiaryBank;
}
通过调用entitymanager.remove()
删除受益人@Override
public void remove(E entity) {
entityManager.remove(entity);
}
但有时候我得到了如下错误,
Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: The DELETE statement conflicted with the REFERENCE constraint "FK_BENEFIC_BENEF_5629CD9C". The conflict occurred in database "XXXX_DB", table "dbo.BENEFICIARY", column 'BENEFICIARY_BANK_ID'. {prepstmnt 596583311 DELETE FROM dbo.BANK WHERE ID = ? [params=?]} [code=547, state=23000]
at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:273)
at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:261)
at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$1200(LoggingConnectionDecorator.java:70)
at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeBatch(LoggingConnectionDecorator.java:1187)
at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeBatch(DelegatingPreparedStatement.java:260)
at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeBatch(JDBCStoreManager.java:1720)
at org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.executeBatch(BatchingPreparedStatementManagerImpl.java:356)
at org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.flushBatch(BatchingPreparedStatementManagerImpl.java:187)
... 56 more
---- Begin backtrace for Nested Throwables
看起来异常是由于打开jpa尝试删除银行表数据之前的受益人表数据。我无能为力,为什么会发生这种情况,因为我给的是CascadeType.ALL它JPA应首先从受益人中删除数据然后从银行表中删除数据 有人对这个问题的解决方案有所了解吗?
提前致谢..