-->
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.  [ 4 posts ] 
Author Message
 Post subject: Getting generated id after save
PostPosted: Fri May 04, 2007 12:15 pm 
Newbie

Joined: Fri Mar 23, 2007 10:13 am
Posts: 8
What is the best way to get the generated id (primary key) right after I save a newly created object?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 1:48 pm 
Beginner
Beginner

Joined: Thu Apr 12, 2007 10:43 am
Posts: 21
Location: Brazil
In my experience (Oracle), you only need to access the id property, as Hibernate will fill it for you when it inserts the new record. I'm using native generators for my id's, and their value is derived from Oracle SEQUENCE's. Cheers,
Roger


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 1:49 pm 
Regular
Regular

Joined: Wed Nov 17, 2004 11:49 am
Posts: 65
Location: Pittsburgh
Code:
Serializable pk = session.save(entity);


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 06, 2007 5:14 am 
Newbie

Joined: Sat May 05, 2007 4:19 pm
Posts: 5
or return ((Integer) session.save(entity)).intValue();


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