Unfortunately, Oracle (at least the version I am using) does not support automatic cascade deletes. Child records must be deleted separately before deleting parent records to avoid constraint violations?
When deleting a parent object with a CascadeType.DELETE set on a @OneToMany, when does Hibernate decide between deleting each child instance one by one and deleting by foreign key in batch.
For example,
PARENT table:
PARENT_ID
1
2
CHILD table:
CHILD_ID PARENT_ID
1 1
2 1
3 2
Deleting the parent could cascade the delete of the children in two ways:
delete from CHILD where child_id = 1
delete from CHILD where child_id = 2
delete from PARENT where parent_id = 1
or
delete from CHILD where parent_id = 1
delete from PARENT where parent_id = 1
I've seen Hibernate do both kinds. What I don't understand is how Hibernate decides which strategy to use. It looks like if the collection is actually initialized, it is likely do the individual deletes in the former example. Yet, this is prone to giving ConstraintViolationException errors if the collection mismatches what is in the session.