tags:

views:

138

answers:

1

I am using Nhibernate in a session-per-request context. When I use session.Update and commit or rollback my transaction, I get an ObjectDisposedException.

the stack trace for this exception is: at NHibernate.Transaction.AdoTransaction.CheckNotDisposed() at NHibernate.Transaction.AdoTransaction.Rollback() at MyService.update(MyItem item) in C:\Projects\MyProject\ItemService.cs:line 121 at MyController.Edit(Nullable`1 pageId, MyItem item, FormCollection collection) in C:\Projects\MyProject\ItemController.cs:line 251

Before I perform the update the transaction contains the following properties: isActive: true, wasCommitted:false, wasRollBacked: false

After I performed the update action the properties have the following values: isActive: false, wasCommitted:true, wasRollBacked: false

Why do I get the exception and why do the booleans change without committing ?

I am using the following code to perform this action:

using (var tx = SessionManager.CurrentSession.BeginTransaction()) 
           {
               try
               {


                   //perform update
                   wysiwygitemRepository.Update(item);

                   // perform an action that raises an exception (because of null value)
                   pageSettingService.SaveSettings(null, item.Id);

                   tx.Commit();
               }

               catch(Exception)
               {
                  tx.Rollback();   
               }
           }

I used fluhmode.none as flushmode, but also tried flushmode.auto

Even if I change the code to the following , I still got the same exception:

using (var tx = SessionManager.CurrentSession.BeginTransaction()) 
       {
           try
           {


               //perform update
               SessionManager.CurrentSession.Update(item);



               tx.Commit();
           }

           catch(Exception)
           {
              tx.Rollback();   
           }
       }
A: 

I already solved the problem.

I used some nhibernate interceptors which caused the problem.

Jan