I'm trying to do some kind of nested transaction behavior using NHibernate transaction management and FlushMode options, but things got a bit confusing after reading too much, so any confirmation of the facts below will be very helpful.
I want to open one big transaction, which is split into small transactions. Imagine the following scenario:
- TX1 opens TX and inserts a Person entry;
- TX2 opens TX and updates this Person name to P2;
- TX2 Transmission:
- TX3 opens TX and updates the name of this person to P3;
- Rollback TX3;
- TX1 Transmission:
I would like NH to send INSERT and TX2 UPDATE to the database, just ignoring what TX3 was when it was dropped.
I tried using FlushMode = Never and only cleared the session after the correct Begins / Commits / Rollbacks were required, but NH always updates the database with the final state of the object, regardless of commits and rollbacks. This is normal? Does NH really ignore transactional controls when working with FlushMode = Never?
I also tried using FlushMode = Commit and opening nested transactions, but I found that since ADO.NET, nested transactions are actually the same transaction.
Please note that I am not trying to achieve all-or-nothing behavior. I look more at the save method. Is there a way to do this (savepoints) with NH?
Thanks in advance.
Philip
source share