-->
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: Is there a way to get the Id back while doing session.save()
PostPosted: Mon Nov 29, 2004 4:15 pm 
Newbie

Joined: Mon Nov 29, 2004 3:59 pm
Posts: 3
Is there a way to get the created Id back when an entity is saved using session.save() and using native id generation?

Something like having id as a return value for session.save() for newly created records.

Here is the code snippet and the hbm.xml file

try
{
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();

session.save(order);

tx.commit();
session.close();
}
catch (HibernateException e)
{
e.printStackTrace();
}

<id name="id">
<column name="ID" not-null="true"/>
<generator class="native"/>
</id>

Hibernate version: -2.1


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 4:16 pm 
Newbie

Joined: Mon Nov 29, 2004 3:59 pm
Posts: 3
Thanks in advance for your help.

(I forgot to put the thank you note in the original message.)

- Shubhada.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 4:28 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Please man, at least read the API. Session.save() returns the generated Id


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 10:07 pm 
Regular
Regular

Joined: Fri Nov 12, 2004 12:07 am
Posts: 57
Location: Beijing,China
Hi,

If the type of your generated id is Integer,then

Integer id=(Integer)session.save(entity);

else if it is String then

String id=(String)session.save(entity);

and etc.

Although this way gets id back is not pretty,but we really can't get the id back in other ways.


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.