-->
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 the autoincrement id of an object just added.
PostPosted: Thu Nov 17, 2005 5:50 am 
Newbie

Joined: Wed Nov 16, 2005 8:52 am
Posts: 2
I have searched through the FAQ's but have not found anything
matching this so I'm hoping someone can help.

We are creating a web application that uses the Springs hibernateTemplate
to tell Hibernate 3 to save objects to our MySQL 5 database.

The table we are saving to in the database has an autoincrement
id field that is the primary key.

The object that we are saving has 0 in the id field till it has been saved, yet
the save method does not return the id or the object just insert
(containing the MySQL generated id).

Is there any way hibernate can get me the id of the object just added.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 7:07 am 
Regular
Regular

Joined: Wed Feb 02, 2005 6:33 am
Posts: 70
Session.save(Object o)

Session.save returns the persistent instance's identifier


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 7:46 am 
Newbie

Joined: Wed Nov 16, 2005 8:52 am
Posts: 2
CollinL,
thanks for your reply.

I've cracked the problem: my DAOHibernate save method was void. I'm going to make a simple change so that it returns the id of the row just inserted.

Cheers anyway,
James.


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.