TransactionScope vs NHibernate Commit

51 views
Skip to first unread message

Graham Bunce

unread,
Feb 8, 2009, 6:19:21 PM2/8/09
to nhusers
Hi,

I was playing around with TransactionScope in my Hibernate Repository
and came up with this simple change:

From this:

NHibernateSessionManager.Instance.BeginTransaction();
try
{
Session.Flush();
NHibernateSessionManager.Instance.CommitTransaction();
}
catch (Exception)
{
NHibernateSessionManager.Instance.RollbackTransaction
();
throw;
}

To This:

using (TransactionScope ts = new TransactionScope())
{
Session.Flush();
ts.Complete();
}

The latter seems so much easier, will pick up any existing
transactions (we do a not of integrating NHibernate with Linq-SQL,
NHibernate with MSMQ etc.) I think, and seems to work ok in basic
single database tests. My Session Mode used to be set to Commit but
now is set to Never.

However, there must be a gotcha with this.. What is it?

Graham Bunce

unread,
Feb 8, 2009, 6:29:28 PM2/8/09
to nhusers
Using NH 2.0.1GA by the way

Ayende Rahien

unread,
Feb 9, 2009, 1:59:13 AM2/9/09
to nhu...@googlegroups.com
There isn't much.
Note that 2.1 has much better support for TransactionScope

Graham Bunce

unread,
Feb 9, 2009, 9:56:01 AM2/9/09
to nhusers
Thanks Ayende.. Can you point me to a link or explain what "better
support" means... as I can use that to help me know what the
limitations of TransactionScope are for 2.0.1GA? I'm currently
building my corporate framework for future application development and
am trying to improve integration with Linq-SQL, COM+ Transactions,
Distributed Transactions etc.

I'm hoping the above will work for all these cases but I've read some
issues with "Ambient Transactions" that I think may cause me some
problems. The links were all old though so I don't know if they are
still relevant.

Fabio Maulo

unread,
Feb 9, 2009, 10:06:04 AM2/9/09
to nhu...@googlegroups.com
If you are working in a new prj I strongly recommend you to use the NH-trunk.
If nothing tremendous happen we will release NH2.1.0Alpha1 in may.
NOTE : In general nothing tremendous happen in NH because we are an serious OSS prj where "pass all existing tests in each commit" (~1600) is a must.

In the trunk we are working in better code-coverage of some supported Dialects as ORACLE, Postgre and MySQL.
After that I want to put my hands in our "xml-binders" to complete an "opera incompiuta".


2009/2/9 Graham Bunce <graha...@hotmail.com>



--
Fabio Maulo

Ayende Rahien

unread,
Feb 9, 2009, 2:06:04 PM2/9/09
to nhu...@googlegroups.com
It is mostly about integrating Sys.Tx with NH.
That is, a commit will automatically flush, listeners will be notifiers, NH.Search will be invoked, etc.
HiLo works now with Sys.Tx, etc.
Reply all
Reply to author
Forward
0 new messages