-->
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.  [ 6 posts ] 
Author Message
 Post subject: How to retrieve values generated by auto_increment in mysql
PostPosted: Fri Feb 04, 2005 10:33 am 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
Hi,

is there a way/a switch to tell hibernate to populate new objects with the keys generated with the auto_increment? e.g. using Statement.RETURN_GENERATED_KEYS with the insert?!

I get all sorts of problems when inserting multiple objects (NonUniqueObjectException), because all objects have the same primary key (0) - I suppose it's just a switch that I'm missing?!

cheers
stefan


Top
 Profile  
 
 Post subject: hibernate.jdbc.use_get_generated_keys true
PostPosted: Fri Feb 04, 2005 10:44 am 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
ok, sorry for that one. Setting

hibernate.jdbc.use_get_generated_keys true

to true obviously does the trick and also solves the update-woes.


Top
 Profile  
 
 Post subject: wrong again...
PostPosted: Fri Feb 04, 2005 11:06 am 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
setting

hibernate.jdbc.use_get_generated_keys true

does not help!

After

Transaction tx = session.beginTransaction();
session.save(unit);
tx.commit();

unit.getId() still returns 0!!!

Is there anything I can do about that?!

cheers
stf


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 04, 2005 12:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
are you using the correct generator? identity or native


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 04, 2005 1:00 pm 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
Whoooopeee! Great!

I'm using hibernate3 and annotations, and i added no GeneratorType to the id, so i guess the defaults were used.

When I change the Annotation to

@Id (generate=GeneratorType.AUTO)

the id's are filled!

Great! Thank you!

Leaves me thinking, what the default actually is: GeneratorType.NONE?

many thx for the help!
stf


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 05, 2005 7:33 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
GeneratorType.NONE is equivalent to generator="assigned",
The application have to fill it itself

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.