-->
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: Insert and sequence
PostPosted: Tue Mar 16, 2004 1:52 pm 
Newbie

Joined: Tue Mar 16, 2004 1:44 pm
Posts: 17
Location: San Jose - Costa Rica
i have a table where the primary key is a sequence

when i insert a record on this table i need to get the last generated id to asociate it with another table

how i can do this ??? how i can get the last genetated id ??

thanks
Ignacio


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 1:54 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
if your primary key is linked to a sequence, just read the doc about id....

when you'll call session.save(myObj);
if myObj id is null then hibernate will hit the sequence to set the id before calling "insert into..."


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 2:04 pm 
Newbie

Joined: Tue Mar 16, 2004 1:44 pm
Posts: 17
Location: San Jose - Costa Rica
delpouve wrote:
if your primary key is linked to a sequence, just read the doc about id....

when you'll call session.save(myObj);
if myObj id is null then hibernate will hit the sequence to set the id before calling "insert into..."


so when i call session.save(myObj) hibernate will do myObj.setID(sequence) ?

Ignacio


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 2:08 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
exactly when session.flush() or commit() is called after session.save(myObj);

don't forget to type your id property as Long or Integer (not int for example) so it can be null at instaciation


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.