roniburd wrote:
No, I'm mean a entity collection.
What I'm seeing is that I have a kind of relationship akin to Order and OrderItem mapped with a Bag. When I issue a deleteById (with HQL) with Order and look at the log I see multiple deletes for each orderitem.
I have set cascade="all-delete-orphan". I'm surely doing something wrong, but don't know what.
Thanks!
No, I see the same thing too. I expected a:
DELETE FROM Child WHERE ParentID = @ParentID
But, it issues a delete for each child record, then for the parent.
I haven't looked at the code but I assume this is because NHibernate knows about objects and not data. It traverses the object graph to the lowest child in the hierarchy then deletes each item in any collections it contains going up the tree generating the delete for each object as it climbs up the tree.
However, what I don't understand is why it issues each command seperately rather than batching them in on command. Seems like alot of traffic could be avoided by sending all the generated deleted in a single command to SQL. Perhaps all back ends don't support this, I don't know. Seems like a db feature the dialect could enumerate.
BOb