-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to get last inserted ID?
PostPosted: Wed Oct 12, 2005 9:59 am 
Regular
Regular

Joined: Sat Sep 03, 2005 9:07 am
Posts: 87
Location: Graz, AUSTRIA
How can I get the last inserted Sequence number?
Is there a method something like that:

SELECT LAST_NUMBER FROM xxx_sequences

To explain why I need this.
I have two forms. On the first form, the user enters some basic data. Then he saves this basic data to the database. On the second page he can add some extra information. To save this extra information, i need the ID, which was generated before, because this extra information belongs to the data on the first page.


Thx for your advice


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 10:04 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
after you do your session.save(Object)
do a session.refresh(Object) and the object should have the generated id from the database stored in its appropriate field

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 10:13 am 
Regular
Regular

Joined: Sat Sep 03, 2005 9:07 am
Posts: 87
Location: Graz, AUSTRIA
Ok, i will try,
Although this isn't really a Hibernate question, but do I have to put this Object which I get through session.refresh(Object) into Session Mode to have it on the next page( I use JSF)...
Thx!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 10:20 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
I don't know much about JSF, but just make sure you pass the pointer to the refreshed object to the next page.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 7:46 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
Actually, after you call session.save(object), object.getID() will be updated. Try it! :-)
Cheers,
Rob


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