Hi James, I've made a sort of TransactionManager the do the same as you post. For every new BeginTransaction if there is a outer transaction open, it is ignored and a couter incremented, if there is a call to RollBackTransaction i just rollback this open transaction (the 'outer') and recreate the session and restart the counter. In the CommitTransaction if it is the outer transaction i do he real commit, if it's not, i just decrement the transaction counter.
Thanks a lot! On Jun 21, 7:13 am, James Crowley <[email protected]> wrote: > The behaviour within a database such as SQL Server > (seehttp://msdn.microsoft.com/en-us/library/ms189336.aspx) is that any inner > transactions are actually ignored entirely - and it is only the outer > transaction's commit/rollback instruction that is executed. I'm not sure if > other databases (oracle, etc) fully support them or not. > As you say, this isn't the behaviour you see within nHibernate. What I ended > up with is my unit of work has a transaction wrapper that implements this > behaviour (I believe Ayende Rahien has a similar implementation), by passing > out "dummy" transactions that do nothing when there's already an outer > transaction active. > > Would be interested to hear other people's solutions to this. > > 2009/6/20 Marcus Rehm <[email protected]> > > > > > > > Hi and guys, > > > I did some more tests and what i realize is that NH don't create a new > > transaction 'b' at sub scope 's' as expected, it's using the same > > transaction 'a' of the outer scope and so, all save actions are > > rolledback at the end. Am i missing something?! > > Maybe the code above don't show what talking about... sorry my > > mistakes... > > > ISession session = factory.OpenSession(); > > > using (TransactionScope s = new TransactionScope ()) > > { > > > // transaction 'a' is active here > > session.Save(obj1); > > > using (TransactionScope t = new TransactionScope > > (TransactionScopeOption.RequiresNew)) > > { > > // transaction 'b' is active here > > session.Save(obj2); > > > t.Complete (); > > } > > > // transaction 'a' is active here > > > using (TransactionScope u = new TransactionScope ()) > > { > > // transaction 'a' is active here > > session.SaveOrUpdate(obj1); > > > } // 'a' rolls back here, > > > //the transaction from 's' is put into Current. > > // transaction 'a' is current, but aborted here > > s.Complete (); > > > } // 'a' is already aborted, so is just removed at this point > > > At this point obj1 and obj2 wasn't saved neither updated at the > > database. > > > Following the expectations based on TransactionScope behavior obj2 > > should be saved and obj1 should be rolledback (save and update), but > > in this case above, obj2 is not being saved in a new transaction. > > > Thanks again! > > > On 20 jun, 00:23, Marcus Rehm <[email protected]> wrote: > > > Hi, > > > > I have a question aboute TransactionScope. > > > If i understood correctly the ISession instance can only have one > > > Transaction, so how NH handle the following code when RequiresNew is > > > passed to the sub scope 't' and transaction 'a' is rolledback in sub > > > scope 'u'? > > > > using (TransactionScope s = new TransactionScope ()) > > > { > > > > // transaction 'a' is active here > > > > using (TransactionScope t = new TransactionScope > > > (TransactionScopeOption.RequiresNew)) > > > { > > > // transaction 'b' is active here > > > > t.Complete (); > > > } > > > > // transaction 'a' is active here > > > > using (TransactionScope u = new TransactionScope ()) > > > { > > > // transaction 'a' is active here > > > } // 'a' rolls back here, > > > > //the transaction from 's' is put into Current. > > > // transaction 'a' is current, but aborted here > > > s.Complete (); > > > > } // 'a' is already aborted, so is just removed at this point > > > > Thanks in Advance! > > -- > James Crowley > Managing Director > Developer Fusion - Connecting developers worldwide > > Developer Fusion Ltd | 58 Sandringham Close | Enfield, EN1 3JH > mob: 07986 624128 web:http://www.developerfusion.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
