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.