NHibernate version: 1.2
[b]database:b]SQL Server 2005
I have a problem when deleting an object that has the following mapping settings:
1. A version field (generated=always)
2. A Bag (cascade=all-delete-orphan)
Right before the delete is done a NHibernate does an update on the object unnecessarily . AFAIK, the object is not dirty - I just want to delete it. NHibernate executes the following queries upon ISession.Delete():
1. A select is done on the object.
2. A select is done to fill the associated bag.
3. An update is done on the parent object causing the value in the version column to be changed.
4. A select query is done to retrieve the new value in the version column.
5. The objects in the bag are deleted.
6. The delete is executed on the parent object, but the WHERE clause does not have the version obtained in step 4, but the version value obtained in step 1.
This causes the delete to fail and throws the optimistic concurrency exception.
I would like to to know what is causing the extra update in step 3, and how I can avoid it and /or why is the version field in the object not set to the value returned in step 4.
If I turn off the cascade on the bag, the delete works as expected with the versioning, but I get no cascading operations. If I remove the version mapping, the cascading works perfectly, but no concurrency checking.
|