-->
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: saveorupdate() returns no id
PostPosted: Fri Apr 11, 2008 4:26 pm 
Newbie

Joined: Fri Apr 11, 2008 4:15 pm
Posts: 1
Hi,

I make hibernate persist an object with the saveOrUpdate() method.
The object has some properties, but before hibernate persists it to the database, it's id is null.
Hibernate generates an id before persisting (as is specified in the mapping file), and saves the object to the database.

From this moment however, the id of the object in memory is still null.
So when I try call saveOrUpdate() again on the very same object (with id == null), hibernate thinks it's a brand new object because id is null and saves it again instead of updating it.

Now I ask myself which is the best way to handle an issue like this.
First saving the object, and then finding it back in the database doesn't seem like a good option to me (performance wise)?

Someone told me that saveOrUpdate() returns the id, which would be ideal, but I checked the JavaDoc and it returns void.

Gr,
nkr1pt


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 11, 2008 4:45 pm 
Newbie

Joined: Fri Apr 04, 2008 2:17 pm
Posts: 15
What does your mapping look like? The XML and the Java code.

When I call session.save(obj), my object is modified and has the generated ID in it. Try using session.save instead

I'd just guess that the object in question is thought to be already saved and it's attempting an update instead of a save. Explicitly calling save might help verify if this is the case


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.