-->
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: saveOrUpdate() reving version on unchanged objects!
PostPosted: Mon Dec 27, 2004 4:06 am 
Newbie

Joined: Mon Dec 27, 2004 3:44 am
Posts: 9
I have the following issue where Foo is using hibernate's automatic versioning:


Foo foo = new Foo();
// Inserts new Foo object with version 0 as expected
foo = session1.saveOrUpdate(foo);

// The following line revs the version of foo to 1 and Session.isDirty()
// will return true even though *no* modifications have been made
// to foo since the first save.
// Why???
foo = session2.saveOrUpdate(foo);


Does hibernate blindly update the version on objects attached to a session via saveOrUpdate()? Even when I have versioing turned off subsequent calls to saveOrUpdate() with an unchanged foo object would still cause session.isDirty() to be true. Why is this? All I want to do is detect whether my remote object has been modified when the user attempts a save. Is there a better best practice to do this? What am I missing here?

Thanks,
Edward


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 27, 2004 5:44 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This is the correct behavior, hibernate does not know the current objectb state in DB.
If you want hibernate to do a select before actually updating, use
Code:
<class select-before-update="true" >


NB: in most case, the default value is better

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 27, 2004 11:28 am 
Newbie

Joined: Mon Dec 27, 2004 3:44 am
Posts: 9
I would have expected saveOrUpdate() to already do a select. If not, how does the saveOrUpdate() method know whether to do an INSERT or UPDATE into the database?

edward


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 27, 2004 11:29 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hum, this is a reference guide and a FAQ question. Just a hint unsaved-value

_________________
Emmanuel


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.