-->
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.  [ 7 posts ] 
Author Message
 Post subject: MySQL Hibernate Identity Generator
PostPosted: Wed Oct 04, 2006 10:52 pm 
Newbie

Joined: Wed Oct 04, 2006 10:20 pm
Posts: 4
Issue:
I am unable to insert using the native generator class. It will only insert if I set the class to increment. The id field is a MySQL AUTO_INCREMENT int datatype. What can I do to fix this?

What I have already done:
I have looked at the documentation and it looks like I should be able to use the identity or native fields with mysql. Also, the increment field is not clusterable.

Hibernate version:3.1.3

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.intraoss.pojo.domain.Testdb" table="testdb">
<id name="id" column="id" type="integer" unsaved-value="0" >
<generator class="native" />
</id>
<property name="name" type="java.lang.String">
<column name="name" length="45" not-null="true" />
</property>
<property name="description" type="java.lang.String">
<column name="description" length="45" not-null="true" />
</property>
</class>
</hibernate-mapping>

Database and Driver:MySQL 5 and the mysql-connector-java-5.0.3-bin.jar


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 04, 2006 11:06 pm 
Regular
Regular

Joined: Tue Sep 26, 2006 11:37 am
Posts: 115
Location: Sacramento, CA
In the past I've successfully used the identity generator in this situation. Not sure what is missing to make native work. Try identity, if still not working something else may be wrong...

Marius


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 04, 2006 11:27 pm 
Newbie

Joined: Wed Oct 04, 2006 10:20 pm
Posts: 4
mseritan wrote:
In the past I've successfully used the identity generator in this situation. Not sure what is missing to make native work. Try identity, if still not working something else may be wrong...

Marius


I have already tried this, it seems to only allow me to do increment. Has anyone done this with this version of the mysql driver and mysql. If there is a configuration issue why would increment work am I missing something.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 04, 2006 11:37 pm 
Regular
Regular

Joined: Tue Sep 26, 2006 11:37 am
Posts: 115
Location: Sacramento, CA
I apologize, I am still missing something. The way I used this in the past is that I created an object, left the id parameter as null (or what ever you set as unsaved-value) and save it to the database. When you save the database fills in the field. After this point you do not change the ID.

At what point are you trying to increment and what?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 05, 2006 12:31 am 
Newbie

Joined: Wed Oct 04, 2006 10:20 pm
Posts: 4
mseritan wrote:
I apologize, I am still missing something. The way I used this in the past is that I created an object, left the id parameter as null (or what ever you set as unsaved-value) and save it to the database. When you save the database fills in the field. After this point you do not change the ID.

At what point are you trying to increment and what?

Sorry for the confusion... Increment is the generator cloass that is being set. So instead of using

<id name="id" column="id" type="integer" unsaved-value="0" >
<generator class="native" />
</id>

or
<id name="id" column="id" type="integer" unsaved-value="0" >
<generator class="identity" />
</id>

I am forced to use:
<id name="id" column="id" type="integer" unsaved-value="0" >
<generator class="increment" />
</id>


Which is not cluster safe and does a Select Max(id) prior to the insert.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 05, 2006 12:31 am 
Newbie

Joined: Wed Oct 04, 2006 10:20 pm
Posts: 4
mseritan wrote:
I apologize, I am still missing something. The way I used this in the past is that I created an object, left the id parameter as null (or what ever you set as unsaved-value) and save it to the database. When you save the database fills in the field. After this point you do not change the ID.

At what point are you trying to increment and what?

Sorry for the confusion... Increment is the generator cloass that is being set. So instead of using

<id name="id" column="id" type="integer" unsaved-value="0" >
<generator class="native" />
</id>

or
<id name="id" column="id" type="integer" unsaved-value="0" >
<generator class="identity" />
</id>

I am forced to use:
<id name="id" column="id" type="integer" unsaved-value="0" >
<generator class="increment" />
</id>


Which is not cluster safe and does a Select Max(id) prior to the insert.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 08, 2006 11:43 am 
Regular
Regular

Joined: Tue Sep 26, 2006 11:37 am
Posts: 115
Location: Sacramento, CA
Pkourinos,

This usage case has been working for me, not sure what is wrong. You are setting an unsaved value of 0, is this what you are using in your new objects?

Marius


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