Business logic inside the process:
- start a transaction
- add item to collection
- do a search ("somethingA")
- delete this item depending on the previous step.
- make a transaction
Im uses cascading syntaxes all-delete-andphans and inverse = true, as in my parent class. When removing an item from the collection, I set .parentObj = null and remove the item from the collection.
When using TemplateFlushMode.Auto I profiled the database and did the following:
- INSERT element
- SELECT related to tosomethingA
- UPDATE parentID (FK for parent) of an element in NULL
(the insertion element is executed as find() is executed to ensure data consistency in the database). The choice is made, and then I would expect DELETE to complete ... but the update is being done to parentID = null .
When executing Session.Flush() before find() , the following happens:
- INSERT element
- SELECT related to tosomethingA
- DELETE Item
When using TemplateFlushMode.Commit changes are made at the end of the transaction, and the element is never inserted:
- SELECT related to tosomethingA
The application I'm working with uses TemplateFlushMode.Auto , so I'm wondering if there is an explanation why cascading does not work if the choice is made between one element and then deleted in the same transaction?
I know that the first answer that appears is "don't add the item to the collection if it is deleted after." But I probably will not change the business logic.
Does anyone know why updating is performed instead of DELETE when using AUTO ? (when using Commit it does not insert an object)
c # nhibernate nhibernate-mapping
AdriΓ‘n poplavsky
source share