I see.  Thanks for the quick response!  I suppose this is one case where 
running off the trunk is a bad idea, as it seems ambient transactions break 
NHibernate at this point.  I can't completely remove the use of 
System.Transactions because it's built-in to NServiceBus, but I'll go back to 
the 2.0 NH release and see if that solves my issue.

Thanks again.
-tyler

________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Fabio 
Maulo
Sent: Thursday, October 16, 2008 1:47 PM
To: [email protected]
Subject: [nhusers] Re: system.transactions

NH2.0 don't support ambient transactions.
In NH2.1 we start some work about it.
If you are using ActiveRecord you can use NHibernateFacilities of Castle + 
CastleTransactionFacilities&services.
2008/10/16 Tyler Burd <[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>>

I'm trying to use System.Transactions with NHibernate (actually, I'm trying to 
use NHibernate/ActiveRecord with NServiceBus, which surrounds message handling 
with a TransactionScope).  I am running off of the trunk.  I'm having a few 
issues, unfortunately.



Basically, I'm trying to do this (pseudo code):



using (var tx = new TransactionScope())

{

  using (var nhSession1 = OpenSession())

  {

    //perform operations and flush session

  }

  using (var nhSession2 = OpenSession())

  {

    //perform operations and flush session

  }

}



So a System.Transactions.TransactionScope already exists when I open and close 
my NH sessions.  Ideally, I'd like those sessions to take part in the larger 
distributed transaction provided by the ambient TransactionScope.  Whenever a 
session is disposed of, though, I get this exception:



"System.InvalidOperationException: Disconnect cannot be called while a 
transaction is in progress.

   at NHibernate.AdoNet.ConnectionManager.Disconnect() in 
d:\oss\nhibernate\src\NHibernate\AdoNet\ConnectionManager.cs:line 156

   at NHibernate.AdoNet.ConnectionManager.Close() in 
d:\oss\nhibernate\src\NHibernate\AdoNet\ConnectionManager.cs:line 122

   at NHibernate.Impl.SessionImpl.Close() in 
d:\oss\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 314

   at NHibernate.Impl.SessionImpl.Dispose(Boolean isDisposing) in 
d:\oss\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 1373

   at NHibernate.Impl.SessionImpl.Dispose() in 
d:\oss\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 1349

   at 
Castle.ActiveRecord.Framework.SessionFactoryHolder.ReleaseSession(ISession 
session) in 
d:\oss\castle-trunk\ActiveRecord\Castle.ActiveRecord\Framework\SessionFactoryHolder.cs:line
 258

   at Castle.ActiveRecord.ActiveRecordBase.FindByPrimaryKey(Type targetType, 
Object id, Boolean throwOnNotFound) in 
d:\oss\castle-trunk\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordBase.cs:line
 1161

   at Castle.ActiveRecord.ActiveRecordMediator.FindByPrimaryKey(Type 
targetType, Object id, Boolean throwOnNotFound) in 
d:\oss\castle-trunk\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordMediator.cs:line
 54

   at Rhino.Commons.ARRepository`1.Load(Object id) in 
d:\oss\rhino-tools\rhino-commons\Rhino.Commons.ActiveRecord\Repositories\ARRepository.cs:line
 59"





I have tried setting the connection.release_mode property to "on_close", and I 
have even tried nesting a TransactionScope with TransactionOption.Suppress (so 
there should be NO ambient transaction), but NHibernate still gives me that 
exception.



I see from the NHibernate.Test.SystemTransactions.TransactionFixture tests that 
opening a TransactionScope within an open session works, but shouldn't opening 
and closing a session within a TransactionScope also work?  Using raw ADO I can 
open and close connections within a TransactionScope and everything works fine.



I'd greatly appreciate it if someone could help me identify whether a bug 
exists in NH or if I'm simply overlooking something.  Thanks.



-tyler





--
Fabio Maulo


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