Today I have checked what sql queries are generated after I call session.Delete method on one of my objects. To my surprise I've got more then 100 queries and most of them (95 to be precise) are just executing of delete statement for child objects. I want to reduce number of delete queries and make sure that for each associated collection of my root object I get only one delete statement.
I found that NHibernate 1.2.1.400 supports one shot delete strategy for child collection. I also checked
http://jira.nhibernate.org/browse/NH-999 issue and I am sure that my mapping is okay. But after committing the transaction I am getting sql constraint exception, which says that parent object tried to be deleted before deleting child objects.
My code looks similar to:
Code:
myRoot.ChildCollection = new ArrayList();
session.Delete(myRoot);
transaction.Commit();
Is there anything else in the mapping I should check except cascade and inverse properties? Should every collection be mapped as cascade="all" inverse="false" for supporting one shot delete strategy? Is it also required for collections associated with base class of my root entity even if I don't need them to be deleted in one-shot (there is a small quantity of elements in the base class collection, so I don't care if the delete statement executes for each item)?