The business logic inside a process is:
Im using cascade all-delete-orphans, and the inverse=true, both in my parent class. When removing the item from the collection, I set the .parentObj = null
and remove the item from the collection.
When using TemplateFlushMode.Auto
, I profiled the Database and the following is done:
(the insert item is done because a find()
is done, to guarantee data consistency in the database). The the select is done, and then I would expect a DELETE
to be performed... but an update to parentID = null
is done.
When performing a Session.Flush()
right before the Find()
, the following happens:
When using TemplateFlushMode.Commit
, the changes are done at the end of the transaction and the item is never inserted:
The app I'm working with is using TemplateFlushMode.Auto
, so I'm wondering, ,is there an explanation why the cascading is not working if a select is done in between one item is added and then removed in the same transaction?
I know the first answer that comes up is "don't add an item to a collection, if it will be removed afterwards". But I rather don't change the business logic.
Does anyone know why an update is being done instead of a delete
when using AUTO
? (when using Commit
it does not insert the object)
I guess you should use the cascade="delete"
option in your mapping file in order to cascade on delete
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With