Recently I started to dig into how to improve the handling of transaction
handling in my code
I notice that there are two way to start a transaction...
ITransaction beginTransaction = Session.BeginTransaction();
Or I can do Session.Transaction.Begin();
The interesting is that
[Test]
public void NHibernateTransact1()
{
ITransaction beginTransaction = Session.BeginTransaction();
ITransaction beginTransaction1 = Session.BeginTransaction();
Assert.Equal(beginTransaction, beginTransaction1); // so if I
call begin transactiontwice.. it return the same transaction
Assert.Equal(beginTransaction, Session.Transaction); // it also
return the same thing as Session.Transaction
}
but if I do something like
[Test]
public void NHibernateTransact2()
{
ITransaction beginTransaction = Session.BeginTransaction();
ITransaction beginTransaction1 = Session.BeginTransaction();
Assert.Equal(beginTransaction, beginTransaction1);
Assert.Equal(beginTransaction, Session.Transaction);
beginTransaction.Rollback();
Assert.NotEqual(beginTransaction, Session.Transaction); //<---
after the rollback they are not the same anymore?
}
for both test the Session is a brand new session from
SessionFactory.OpenSession();
So I am curious of what is the different between the two... and when should
I use one vs the other?
Any help on this would be greatly appreciated
Thanks,
Hoang
--
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.