Using Grails 2.4.4, Hibernate 4.3.6.1 plugin...
We have a domain object with a parent/child one-to-many relationship using a hasMany/belongsTo. When deleting the parent record, Grails cascades the deletes to the child records. However, when looking at the SQL, I see that Grails is fetching the child records and deleting them one-by-one using delete ... where id = ? and version = ?
This is a horribly inefficient way to delete the child records and I'm fairly sure Grails didn't do this when I initially wrote this code (I can't find anything that specifically causes this behavior).
I would expect Grails/Hibernate to run a query more like:
delete from Child where parent_id = ?
So that all child records are deleting in one query, instead of thousands of queries.
Is there something in the mappings/config that would cause Grails to behave in this manner?
version = ?
part from the delete statement. – Aaron