-->
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.  [ 1 post ] 
Author Message
 Post subject: Invalid SQL INSERT statement
PostPosted: Tue Feb 09, 2010 7:16 am 
Newbie

Joined: Mon Sep 01, 2008 6:31 am
Posts: 11
Location: Zwolle, The Netherlands
Today have come across a strange error with the inserting of transient objects. Which leads me to question whether I understand how it works (hence this post :-) Am using sessions in separate generic DBAccess layer implementation. which is not always aware of which object is new (transient) and which one is loaded (persistent). To make sure that I have the latest version of an object before starting edit I wanted to use the Lock(o, LockMode.Read) call, but since it fails for transient objects I first call SaveOrUpdate(o) just to be sure.

Code:
With GetCurrentSession()
   .SaveOrUpdate(o) 'Just to prevent errors on lock call
   .Lock(o, LockMode.Read) ' making sure I have latest version (will cause exception if I don't)
End With


Now comes the issue, when then making changes to the object there is no problem at all until I try to save the newly created object. This runs the following code, so in fact it just calls SaveOrUpdate on my associated new object again and then commits the session. This immediately raises an exception since the generated SQL INSERT statement does not contain any of the changes I made to the object since the original SaveOrUpdate call was made. Instead, it tries to insert NULL values (whereas the actual properties have all got valid values)

Code:
With GetCurrentSession()
   Using .BeginTransaction
      .SaveOrUpdate(o)
      .Transaction.Commit()
   End Using
End With


Can someone explain why this behaviour is as expected? (or is this a bug?) I expected that after the first saveorupdate NHibernate automatically monitors the changes made to the properties.

_________________
Theo
Nairobi, Kenya


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

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.