I think that using a TransactionScope object to wrap all your method calls
should work in this case.

 

From: [email protected] [mailto:[email protected]] On Behalf
Of Stuart Campbell
Sent: quinta-feira, 15 de Janeiro de 2009 10:29
To: [email protected]
Subject: [nhusers] Nested transactions

 

What's the recommended way to support nested transactions in NH?

Basically, I'm using session-per-request and my repository methods wrap all
calls in a transaction like this...

var tran = session.BeginTransaction();
try
{
    // do work here

    tran.Commit();
}
catch
{
    tran.Rollback();
    throw;
}

But I also want multiple repository calls to be contained in a logical
"business" transaction, like this (note that all repositories expose
BeginTransaction which returns an ITransaction wrapper):

var outerTran = accountRepository.BeginTransaction();
try
{
    accountRepository.Save(account);

    notificationRepository.Save(notification);

    outerTran.Commit();
}
catch
{
    outerTran.Rollback();
    throw;
}

This doesn't work because outerTran reports that it has been committed as
soon as the first Save() operation commits. I'm obviously missing something
fundamental here and would be grateful if someone could point me in the
right direction. 

If I have some time today I'll try looking through the NH code to try and
understand the internals better. In the meantime any pointers would be
welcome.

thanks

Stu




--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to