-->
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: Calling Session.save() on an existing entity
PostPosted: Wed Jan 21, 2004 6:59 pm 
Newbie

Joined: Sun Oct 26, 2003 4:46 pm
Posts: 16
Location: Tallinn, Estonia
Hello,

I just accidentally called Session.save() on an object that was loaded by that same session. And it worked perfectly - it updated the object with the values I had set.

Until now I had the impression that you should call save() on new objects that should be inserted and update on an existing object. So have I misunderstood the purpose of save() or this is just a lucky case where this worked but I shouldn't rely on it?

_________________
best regards,
erik


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 4:50 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
save(), update(), saveOrUpdate() on an object attached in the session is silently ignored.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 10:29 am 
Regular
Regular

Joined: Mon Nov 24, 2003 6:36 pm
Posts: 105
Hibernate is not sending the update because of your sess.save() call.
It likely detected the change to the loaded object.

Generally you want to use sess.save when you are doing an insert.

When doing an update, generally the model is
session.load (object)
//call setters on object
tx.commit

no explicit sess.save needed- hibernate proxies your objects, so it "knows" the object is dirty.


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.