-->
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 do you retreive the id from an identity?
PostPosted: Sun Apr 16, 2006 10:52 pm 
Newbie

Joined: Tue Apr 11, 2006 5:11 pm
Posts: 4
<id name="JobId" column="JOB_ID" type="System.Decimal">
<generator class="identity"/>
</id>

Can anyone tell me how I can retrieve the ID when saving if the generator class is identity?

Basically, in the above code snippet, I have a table with an identity column that creates a new JobId for me, I need the value of the newly created JobId when I perform a save() so that I can use it to populate the rest of my DAO's.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 4:46 am 
Beginner
Beginner

Joined: Sun Jul 10, 2005 12:11 pm
Posts: 32
Location: Hertfordshire, England
From the Hibernate API:

Quote:
public Serializable save(Object object)
throws HibernateException
Persist the given transient instance, first assigning a generated identifier. (Or using the current value of the identifier property if the assigned generator is used.) This operation cascades to associated instances if the association is mapped with cascade="save-update".
Parameters:
object - a transient instance of a persistent class
Returns:
the generated identifier
Throws:
HibernateException


In other words, the Session.save({object}) function returns the generated identifier.

HTH

_________________
--
Christian Ashby
Spiralinks, Inc.


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.