-->
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: last inserted unique id from auto increment in mysql
PostPosted: Sun Feb 01, 2004 10:07 pm 
Newbie

Joined: Thu Nov 27, 2003 9:11 am
Posts: 5
Say in an order table, the id is unique and auto incremented by mysql, so when an Order object is prepared for saving, no id is set. How can one get the last inserted (mysql generated) unique id from the table which will be set to the Order object without resorting back to JDBC.

This id will then be used to set the id property in the Order object and the orderId property in a related OrderItem object which will also be saved.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 5:51 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Isn't identity fits your needs. I don't know if it's supported by MySQL however.

At last, write your own IdentityGenerator (id and dialect package). Have a look at the code.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 7:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Hibernate does all that for you, thats just what its made for :) Just save away your object and hibernate will set all the ids and associations for you. Simply use the identity generator for mySql auto-increments.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 11:22 pm 
Newbie

Joined: Thu Nov 27, 2003 9:11 am
Posts: 5
Sorry for the bother. This has tested my patience for a couple of days after focusing wrongly on a different area.

I guess the problem is with mysql. I found out that weird things happen if a table with a name of 'order' exists. I was testing their gui control center to create this table. It was successfully made but when manipulated using straight sql (or tools which use it e.g. hibernate), errors arise. The bad thing is that 'order' is not in the downloaded mysql manual's list of reserved words. Anyway, all unnecessary errors were gone once I changed the name from 'order' to another such as 'orders', 'tblOrder' and the like. And hibernate run smooth as silk.

Yeah hibernate rules. Hibernate shall monopolize! Heeh heeh he!


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.