These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: nhibernate + mono + transactions
PostPosted: Mon Jul 09, 2007 10:52 am 
Newbie

Joined: Wed May 30, 2007 2:18 pm
Posts: 14
Hi all,

I'm having some trouble getting transactions to work. I am using NHibernate 1.2.0 GA with the latest Mono and MySql.

I tried to get the simple example from the documentation but I receive the following error:
Code:
Server Error in '/' Application
Object reference not set to an instance of an object

Description: Error processing request.

Error Message: HTTP 500. System.NullReferenceException: Object reference not set to an instance of an object

Stack Trace:

System.NullReferenceException: Object reference not set to an instance of an object
  at NHibernate.Transaction.AdoTransaction.AfterTransactionCompletion (Boolean successful) [0x00000]
  at NHibernate.Transaction.AdoTransaction.Commit () [0x00000]
  at WebApplication1._Default.Page_Load (System.Object sender, System.EventArgs e) [0x00000]
  at System.Web.UI.Control.OnLoad (System.EventArgs e) [0x0008d] in /home/users/bchan/mono-trunk/mcs/class/System.Web/System.Web.UI/Control.cs:938
  at System.Web.UI.Control.LoadRecursive () [0x00085] in /home/users/bchan/mono-trunk/mcs/class/System.Web/System.Web.UI/Control.cs:1350
  at System.Web.UI.Page.InternalProcessRequest () [0x0020b] in /home/users/bchan/mono-trunk/mcs/class/System.Web/System.Web.UI/Page.cs:1358
  at System.Web.UI.Page.ProcessRequest (System.Web.HttpContext context) [0x00058] in /home/users/bchan/mono-trunk/mcs/class/System.Web/System.Web.UI/Page.cs:1193

07/09/2007 13:52:06


The main code looks like this:
Code:
      protected void Page_Load(object sender, EventArgs e)
      {
         ISession session = NHibernateHelper.GetCurrentSession();

         ITransaction tx = session.BeginTransaction();
         if (tx == null)
            throw new ApplicationException("TX IS NULL");
         Cat princess = new Cat();
         princess.Name = "Princess";
         princess.Sex = 'F';
         princess.Weight = 7.4f;

         session.Save(princess);
         //session.Flush();
         tx.Commit();

         NHibernateHelper.CloseSession();
      }


If I comment out the two transaction lines and use a session.Flush() instead it creates the record correctly. Am I missing something for transactions to work?

Thanks.


Top
 Profile  
 
 Post subject: Did you find a solution to this?
PostPosted: Thu Sep 06, 2007 5:29 am 
Regular
Regular

Joined: Wed Aug 15, 2007 7:37 am
Posts: 73
I get the same problem. Seems a bit weird that such an elementary thing doesn't work though.

Steve


Top
 Profile  
 
 Post subject: Further...
PostPosted: Thu Sep 06, 2007 7:11 am 
Regular
Regular

Joined: Wed Aug 15, 2007 7:37 am
Posts: 73
Tracked this down to line 318 in Dispose(bool) in AdoTransaction:

[code]
if (trans != null)
{
[b]trans.Dispose();[/b]
}

[/code]

Commenting out that call makes things work properly. This is using the latest MySQL .Net 5.0.8.1 driver.

Any help appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 06, 2007 12:19 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Looks like a bug in the MySQL driver.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 06, 2007 12:30 pm 
Regular
Regular

Joined: Wed Aug 15, 2007 7:37 am
Posts: 73
Thanks for the response.

What confuses me is why under the MS .Net implementation it works ok though, using all the same libraries. Given that, it would seem to make more sense if it was a problem in Mono itself. The MySQL Transaction.Dispose() is empty so. I don't have enough knowledge about what NHibernate does with transactions or what might be going on in Mono.

I'm surprised this isn't more wdespread though, unless most people are using NHibernate under Visual Studio.

I'm at a bit of a loss TBH.

Steve


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.