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: NHibernate Update -->
PostPosted: Mon Nov 19, 2007 5:44 pm 
Newbie

Joined: Thu Jul 12, 2007 9:07 am
Posts: 4
What i am trying to do is, update the SQL DB through the NHibernate objects.

I do a series of steps to Add a new instance of my table object, save the that object and then flush it as shown below. I have tried 2 ways to append the changes to DB. First way is to BegingTransaction-->commit-->close
The second way i have tried is, save()-->flush()

Code:
           
            ITransaction transaction = Session.BeginTransaction();
            BrunMainPost dt = (BrunMainPost)Session.Get(
                typeof(BrunMainPost), Rvs.PostDt);

            dt.RVSData.Add(Rvs);
            Session.Save(dt);
            transaction.Commit();
            Session.Close();
            //Session.Flush();
            return dt;



Every thing works fine until Save.
However the moment i step over to either the Session.Flush() OR transaction.commit(), i get an exception that says the following:

Message = NHibernate:
"could not update: [Muni.DataAccess.Brunello.MainRVS#0]
[SQL: INSERT INTO MainRVS
(cusip, dated_date, name, adv_rfnd_dt, brunpost_dt, id)
VALUES
(?, ?, ?, ?, ?, ?)]


These(cusip, dated_date, name, adv_rfnd_dt, brunpost_dt, id) are the Column fields that my table object has.

Now when i step ove rthese errors, and try running the application again, i get the following error

System.NullReferenceException' occurred in System.Windows.Forms.dll - Object reference not set to an instance of an object.

I drilled down in this error and find out that there is an inner exception in the above error, that says the following (i am only included 6 properties instead of 42 that are in the error to save the space here):

Inner Exception: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

Can someone help me out here, what could be wrong?
(1) I am using sql DB
(2) There are 2 tables that i am using.
- table 2 has 42 columns and table 2 has 2 columns.
- the table 2 is connected with table 1 through a Foreign Key.
(3) In table 1 and in table 2, there is a DateTime column that is set to "Not Allow Nulls"

What do you guys think?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 19, 2007 6:23 pm 
Newbie

Joined: Thu Jul 12, 2007 9:07 am
Posts: 4
While, i have the break point inserted and am running in the debugger; the value get added to the object. However my goal is to save these changes to the DB. Even though the values appear in the Grid during Debugging, they do not get added to the Database.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 19, 2007 6:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
Looks like you haven't initialize one of your DateTime properties. By default, a .net DateTime have default value of 01/01/0000 (if I am not mistaken). Either change the column to nullable and change the property to "DateTime?", or initialize your property to some value that is accepted by the underlying DBMS.

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 19, 2007 8:13 pm 
Newbie

Joined: Thu Jul 12, 2007 9:07 am
Posts: 4
Thanks for the reply.

So, i have total of 42 properties in my object. 10 of them are datetime. I have initialized all of those 10 to Datetime.Now. Previously, i had them initialized to DateTime.MinValue;

I will check again if there is any property that i am missing some how. But i am confident that, thats not the problem.

Will update in a bit.


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.