-->
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: How to know the id of newly saved object?
PostPosted: Thu Jun 28, 2007 11:41 am 
Beginner
Beginner

Joined: Sat May 12, 2007 2:55 am
Posts: 24
Hi all,

i am newbie to hibernate and wanted to know how can we know the recenty saved objects' id without firing another query?
i am using hierbate 3.0.

I have a jsp form let say it is asking for name and address.
the user table of mysql have three fields called id,name and address.
userObject.setName() and userObject.setAddress() and
while accepting data from user and using session.save(userObject) ,
is there anyway to know the recently added objects id?

id is the primary key on the table and is auto-increment.

thanks in advance..
nirav


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 12:55 pm 
Newbie

Joined: Thu Jun 28, 2007 7:10 am
Posts: 2
Location: Slovakia
session.save(object) return ID (the generated identifier) as Serializable.

Another possibility is ask userObject for id "object.getId()" after you save it (if you have ID promoted to object).


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.