When I delete a record in a table, related record should be deleted in another table. But I receive instead:
java.sql.BatchUpdateException: Batch entry 0 update child_table set parent_table_id=null where parent_table_id=63 was aborted
The exception above is thrown against the following settings:
@OneToMany(cascade = javax.persistence.CascadeType.ALL, targetEntity = ChildTable.class)
@JoinColumn(name = "parent_table_id")
@org.hibernate.annotations.Fetch(FetchMode.SUBSELECT)
public List<ChildTable> getTables() {
return tables;
}
If I'm not mistaken, with such annotations, when a record is deleted in ParentTable, corresponding relation should be deleted in Child one. It tries to become "null" (because corresponding record exists no more) before complete deletion. This id column is "not null". When I make it be "null" (just for testing this case) everything works correctly.
Could you help me understand what is the real problem behind this?
Thank you in advance.