-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problem with flushing the session
PostPosted: Tue May 08, 2007 5:10 pm 
Newbie

Joined: Tue May 08, 2007 4:39 pm
Posts: 5
Location: Leipzig, Germany
Hello,

I'm new with NHibernate and I just tried to walk thru the Hibernate Quick Start Guide.

I made a .NET class representing an entry of a table-row, wrote the mapping fileand created the config file just it is described in the guide.

Opening sessions and beginning transactions works all fine. Also I could read entries from database. However, when I modify a field in the class and try to flush it, I get a NHibernate.ADOException as follows.

Here is a codesnippet:

Code:
         ISessionFactory factory = cfg.BuildSessionFactory();
         ISession session = factory.OpenSession();
         ITransaction transaction = session.BeginTransaction();

         SalesAgent sa = (SalesAgent)session.Load(typeof(SalesAgent), 200);
         sa.ChangeDate = DateTime.Now;
         session.Flush();
         transaction.Commit();
         session.Close();


At the Flush-Statement this exception-message occurs:
Code:
could not update: [Test01.SalesAgent#200][SQL: UPDATE [it2m].[SalesAgent] SET MainSalesAgentID = ?, SalesAgentSK = ?, PartnerID = ?, LogInUserName = ?, LogInPassword = ?, MasterPassword = ?, Enabled = ?, Supervisor = ?, ChangeDate = ?, ValidFrom = ?, ValidTo = ? WHERE SalesAgentID = ?]


My first thought was the record values could not be read from the class, but the generated SQL seems OK for me:
Code:
NHibernate: UPDATE [it2m].[SalesAgent] SET MainSalesAgentID = @p0, SalesAgentSK = @p1, PartnerID = @p2, LogInUserName = @p3, LogInPassword = @p4, MasterPassword = @p5, Enabled = @p6, Supervisor = @p7, ChangeDate = @p8, ValidFrom = @p9, ValidTo = @p10 WHERE SalesAgentID = @p11; @p0 = '0', @p1 = '1392', @p2 = '1ae106ed-5e6f-465c-809d-00efb0027a8d', @p3 = 'ABC', @p4 = 'd41d8cd98f00b204e9800998ecf8427e', @p5 = 'masta', @p6 = 'True', @p7 = 'False', @p8 = '08.05.2007 22:51:41', @p9 = '09.01.2007 00:00:00', @p10 = '31.12.9999 00:00:00', @p11 = '200'


I'm using MS SQL Server 2005 Express and NHibernate V1.2.0

I hope for any help! ;-)

Regards!


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 11:03 am 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
Just a quick question, why don't you call save instead?

Code:
session .SaveOrUpdate(sa)


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 11:18 am 
Newbie

Joined: Tue May 08, 2007 4:39 pm
Posts: 5
Location: Leipzig, Germany
I've also tried a call the Save-method, which leads to the same exception when I commit the transaction.

Til now I've figured out, the problem is one field in the table (MainSalesAgentID) which allows NULL values. If I set this property to a valid value and flush/save the session, all works fine.

Does anyone know how to map a "nullable" integer field into a CLR value-type?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 11:22 am 
Newbie

Joined: Tue May 08, 2007 4:39 pm
Posts: 5
Location: Leipzig, Germany
susad wrote:
Does anyone know how to map a "nullable" integer field into a CLR value-type?


I've just found the answer:

Code:
      private int? _mainSalesAgentID;
      public int? MainSalesAgentID
      {
         get { return _mainSalesAgentID; }
         set { _mainSalesAgentID = value; }
      }


This does the work!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.