-->
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.  [ 3 posts ] 
Author Message
 Post subject: updating a previously loaded object question
PostPosted: Wed Oct 01, 2003 6:44 am 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
Hi,

If I try to update an object loaded in the same session, by calling one of the setter and then flush(), if the new value of the property is the same like the old one, no update is issued to the DB.

Session session = ...
Person person = session.find(...)
person.setName("sameName") // same value as in the person object
session.flush();
session.close();

On the other hand, if I load Person in a previous session and try to update in a new one, an update is issued to the DB even if nothing changes in the object's fields

Session session = ...
Person person = session.find(...)
session.close();

Session session1 = ...
person.setName("sameName") // same value as in the person object
session1.update(); // or saveOrUpdate()
session1.flush();
session1.close();

Why is that? Can I achieve the same functionality as in the first case?

Thanks,

--steve


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 7:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
In Hibernate 2.1, you may enable select-before-update, which means that Hibernate will grab a snapshot from the database, and decide if it really needs to update the row. Otherwise, Hibernate has no snapshot when update() is used, so it must send an update. Also in 2.1, you can reassociate the object with the session using lock(), which does NOT force an update.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 9:56 am 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
Thanks Gavin.

--steve


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