I put this in another post but I felt like it deserved its own thread: I noticed that when I set cascade="all" on an associated collection, Nhibernate would load all of the associated items and then delete them one by one while attempting to load each childs asscociations and then deleting them. I can easily do this with cascade delete in the databse so I wanted to let the database handle the cascading deletes for performance reasons. I had a collection an enity that had a collecion of 43 other entities and over 700 queries were sent to the database to delete all the associations. This is highly unacceptable.
With the trigger in place, I try to delete the root entity with NHibernate and I get this error:
Duplicate identifier in table for RemoteNet.Northrop.IbisWork.Domain.Model.SubStep: 2172
This is a terrible exception message because I really dont have 2 identifiers in the same table. What is happening is that after a delete operation, NHibernate is calling AbstractEntityPersister.Check which verifies that only 1 item was deleted by the query. The database is returning a recordsaffected result larger than 1 because all of the cascade deleting that occurs. how can I get around this?
|