-->
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: Getting last inserted ID
PostPosted: Tue Sep 13, 2005 5:20 pm 
Beginner
Beginner

Joined: Thu Sep 08, 2005 9:24 pm
Posts: 20
Location: Boise Idaho
I've been googling and searching around and can't find a clear example of how to retrieve the id of the last record inserted after using the Session.save() method...I know this must be simple, how is this done? I noticed it is selecting the identity when I view the sql output...would I have to query the session again to get it?

Please provide an example or a link to where this is found in the documentation, I could not find it.

I'm using Hibernate 3.0.5

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 13, 2005 5:31 pm 
Regular
Regular

Joined: Sun May 08, 2005 2:48 am
Posts: 118
Location: United Kingdom
When you have an object, its "Id" property will be set with the key you are looking for the Object ID.

Session.save(yourClass);
long id = yourClass.getId();

The one defined in the mapping by:

<id name="Id" type="long" column="id">
<generator class="native" />
</id>


Top
 Profile  
 
 Post subject: duh
PostPosted: Tue Sep 13, 2005 5:36 pm 
Beginner
Beginner

Joined: Thu Sep 08, 2005 9:24 pm
Posts: 20
Location: Boise Idaho
That's so easy I feel dumb for asking...

Thanks!!


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.