-->
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: Return generated keys from mysql auto increment
PostPosted: Thu Oct 14, 2004 10:01 pm 
Newbie

Joined: Fri Jul 02, 2004 5:17 am
Posts: 7
Hibernate version:2.16

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:
MySQL 4.0.18

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Saw this link that demonstrate the returning of generated keys from connector/J.

http://dev.mysql.com/tech-resources/art ... ctorj.html

Does hibernate have any methods that can help me get back the generated id from auto increment column??

All help appreciated!!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 15, 2004 11:24 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
Look here:
public class MySQLDialect {
...
public String getIdentitySelectString() {
return "select last_insert_id()";
}
....
}


If you don't use "assigned" generator, Hibernate should set the generated ID in the object model. As I understand for MySQL "native" generator should use MySQL AUTO_INCREMENT functionality:

session.save(obj);
session.flush();
assert (obj.getId() != null);

_________________
Leonid Shlyapnikov


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.