-->
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.  [ 2 posts ] 
Author Message
 Post subject: Reattaching objects
PostPosted: Wed Nov 02, 2005 4:48 am 
Newbie

Joined: Wed Nov 02, 2005 4:03 am
Posts: 7
Hibernate version: 3 / JBoss 4.0.3
Name and version of the database you are using: Oraclie 9i

Which is the right way to reattach an object to a new session?

I don't want to change the object, but only want to be able to access lazy associations.

I've tried merge() and update(), but both of them will always update the object in database at end of session. If read the FAQ "Hibernate updates an object in the database, when I didn't change anything!", but there are no "is dirty" comments in the log.

What is wrong? How can I find out what is dirty?

Another question: on (desired) updates, Hibernate always updates every column, not just those whose values changed. Is this desired behaviour, or did I do something wrong?

Marcus.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 1:10 pm 
Newbie

Joined: Thu Jan 20, 2005 12:21 pm
Posts: 9
Hi,

As far as updates are concerned. Hibernate uses some heuristics to find out if your object is dirty, but in any case, by default an update() will always save your object. See Section 11.7 in the Hibernate reference manual.

To make sure objects are not updated when they have not changed, map the class with select-before-update="true".

Using merge() will work whether or not a persistent object is already part of the session. The only thing to keep in mind when using merge() is that the object itself will remain detached, but it returns the persistent instance associated with the session. Using saveOrUpdate() will only succeed if the object is not already associated with the session.

Cheers
Erik


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