-->
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: MySQL: Problem with AUTO_INCREMENTed primary keys
PostPosted: Tue Aug 31, 2010 5:08 pm 
Newbie

Joined: Tue Aug 31, 2010 5:00 pm
Posts: 8
MySQL: How do you get the next auto_incremented number when merging? If I set it to the correct value it works but how are you supposed to know which number that is? I get exceptions when trying to merge objects which have the auto_incremented primary key set to null. I don't want to set it. I want it to be auto_incremented. Do I change the database or is there something you can do in the Hibernate JPA code?


Top
 Profile  
 
 Post subject: Re: MySQL: Problem with AUTO_INCREMENTed primary keys
PostPosted: Wed Sep 01, 2010 7:12 am 
Newbie

Joined: Tue Aug 31, 2010 5:00 pm
Posts: 8
Is it impossible? Not even with native queries? I create a new object which I want to persist in the database. The id is auto_incremented.


Top
 Profile  
 
 Post subject: Re: MySQL: Problem with AUTO_INCREMENTed primary keys
PostPosted: Wed Sep 01, 2010 8:03 am 
Regular
Regular

Joined: Sun Feb 14, 2010 3:29 pm
Posts: 58
Location: USA
You might have misunderstood the meaning and usage of "session.merge()" method. It's used to MODIFY a persisted object. That's mean, the object you are merging with should already be loaded in previous session and it is detached mode, in another word, it should already have an existing ID value for this object at this point, and no new value is generated during merge().

Your identity ID property(MySQL auto_increment in your case) is used when you go persist a new object. And if you map this right, it should be auto generated for you and you may retrieve it after object is persisted.

See http://docs.jboss.org/hibernate/stable/ ... e-detached

_________________
Zemian Deng
------------
Need a Java Scheduler? Try
http://bitbucket.org/timemachine/scheduler


Top
 Profile  
 
 Post subject: Re: MySQL: Problem with AUTO_INCREMENTed primary keys
PostPosted: Wed Sep 01, 2010 8:08 am 
Newbie

Joined: Tue Aug 31, 2010 5:00 pm
Posts: 8
I got it to work. I changed the database table definition some and loaded the new auto_incremented object with a find after merging it.
KEY `TEST_ID_KEY` USING BTREE


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.