Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
1.2:
Transaction.commit():
I have a sql server table with a Datetime Column with Allow NULL. I am loading all the records from that table via NHibernate then I iterate through the collection take out my required Record(Object) from that collection, make some changes to it ( I assign value to DateTime field) and then I save and commit this object. All this happens in a single Session.
My problem is that when I commit the transaction I get an exception saying that DateTime should be between 01/01/1700 to 31/12/9999.
When I enabled the logging of SQL queries I found that when I call transaction.commit() it sends updates for all the records in the collection whereas I expected it to only send the updates for the record which I changed. Anyways, as it is sending update for every record in the collection some of them have NULL datetime field and due to which the whole transaction fails.
Following is the algorithm I am using.
Session = CreateSession();
Transaction = Session.BeginTransaction();
Queue = GetQueue(QueueId);
Message m;
foreach( Message m in Queue)
{
If ( Message.status.equals("NEW") )
{
m = Message;
break;
}
}
m.processingTime = DateTime.NOW;
Session.Save(m);
Transaction.Commit();
Session.Close();
I know that whenever we commit a transaction it synchronizes with the database but I expected only changed records to be updated not everything.
Lastly I know that it is not the correct way to do what I have done. I should have a specific HQL query fetching the record directly from database. But I am testing different things so it would help me understand the behaviour.
Help is much appreciated
Thanks
Syed