-->
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.  [ 9 posts ] 
Author Message
 Post subject: problems using auto_increment and generated ID's
PostPosted: Wed Oct 06, 2004 2:39 pm 
Newbie

Joined: Mon Sep 27, 2004 7:49 pm
Posts: 3
Hello all! I'm having some trouble making hibernate co-operate with the auto_increment PK's i've set up with MySQL. It's the same error message as in
http://forum.hibernate.org/viewtopic.php?t=932807 this thread, but i've definitely already set the MySQLDialect. Any help that anyone can give as to what's causing this would be most appreciated.

(If i understand it correctly, it'd be a bad idea to explicitly declare the generator class to be "increment", as we'd like to scale to a cluster eventually.)

Thanks,
A

Hibernate version: 2.1.2

Mapping documents:
<class ...
<id name="id" type="long">
<generator class="native"/>
</id>
...
</class>

Full stack trace of any exception that occurs:[java] net.sf.hibernate.JDBCException: Could not save object
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:172)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:705)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:177)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:83)
[java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
[java] at org.apache.tools.ant.Task.perform(Task.java:364)
[java] at org.apache.tools.ant.Target.execute(Target.java:341)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:369)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
[java] at org.apache.tools.ant.Main.runBuild(Main.java:673)
[java] at org.apache.tools.ant.Main.startAnt(Main.java:188)
[java] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
[java] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
[java] Caused by: net.sf.hibernate.JDBCException: Could not save object
[java] at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:783)
[java] at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
[java] at AJTesting.TestDesignObjects.main(TestDesignObjects.java:71)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:324)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:193)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:130)
[java] ... 13 more
[java] Caused by: java.sql.SQLException: General error message from server: "Table '*******.hibernate_unique_key' doesn't exist"
[java] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
[java] at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
[java] at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
[java] at com.mysql.jdbc.Connection.execSQL(Connection.java:2247)
[java] at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1586)
[java] at net.sf.hibernate.id.TableGenerator.generate(TableGenerator.java:93)
[java] at net.sf.hibernate.id.TableHiLoGenerator.generate(TableHiLoGenerator.java:59)
[java] at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:765)
[java] ... 21 more
[java] --- Nested Exception ---
[java] net.sf.hibernate.JDBCException: Could not save object
[java] at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:783)
[java] at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
[java] at AJTesting.TestDesignObjects.main(TestDesignObjects.java:71)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:324)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:193)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:130)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:705)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:177)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:83)
[java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
[java] at org.apache.tools.ant.Task.perform(Task.java:364)
[java] at org.apache.tools.ant.Target.execute(Target.java:341)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:369)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
[java] at org.apache.tools.ant.Main.runBuild(Main.java:673)
[java] at org.apache.tools.ant.Main.startAnt(Main.java:188)
[java] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
[java] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
[java] Caused by: java.sql.SQLException: General error message from server: "Table '*******.hibernate_unique_key' doesn't exist"
[java] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
[java] at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
[java] at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
[java] at com.mysql.jdbc.Connection.execSQL(Connection.java:2247)
[java] at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1586)
[java] at net.sf.hibernate.id.TableGenerator.generate(TableGenerator.java:93)
[java] at net.sf.hibernate.id.TableHiLoGenerator.generate(TableHiLoGenerator.java:59)
[java] at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:765)
[java] ... 21 more

Name and version of the database you are using: MySQL 4.0.11a-gamma[/url]


Top
 Profile  
 
 Post subject: This is what I use
PostPosted: Wed Oct 06, 2004 4:20 pm 
Beginner
Beginner

Joined: Tue Jun 22, 2004 7:50 am
Posts: 25
I'm using MySQL (as my test database server) as well, this is my create script:

Code:
        CREATE TABLE document_template (
            templateId INTEGER PRIMARY KEY NOT NULL,
            name VARCHAR(100),
            description VARCHAR(255),
            bytes BLOB
        );


and this is the mapping file

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
    PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>

    <class name="LetterTemplate" table="document_template">
   
        <id name="id" type="int" column="templateId" unsaved-value="0">
            <generator class="increment"/>
        </id>

        <property name="name" type="string">
            <column name="name"/>
        </property>

        <property name="category" type="string">
            <column name="description"/>
        </property>
       
        <property name="content" type="BinaryBlobType">
            <column name="bytes"/>
        </property>

    </class>
   
</hibernate-mapping>



I did use AUTO_INCREMENT in the create script and "native" as the generator and that worked as well but wasn't portable to MSSQL (our production DBMS) so I switched to this scheme which works for both. Hope this gives you some help.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 06, 2004 6:01 pm 
Newbie

Joined: Wed Sep 01, 2004 1:32 pm
Posts: 9
Location: (eastern) North Carolina
Quote:
"Table '*******.hibernate_unique_key' doesn't exist"


'*******.hibernate_unique_key' is not visible. (Is this MySQL's version of sequences for id generation?) This can be because:

    1) object doesn't exist
    2) object exists in a schema other than the current schema
    3) Unlikely but, current user does not have execute privileges on this object.


I suspect that the the object in question exists but is not in current schema.

I had this situation in my application and originally had been using 'native' id generator. For my dialect, Hibernate had automatically created hibnate_sequence in default schema. To allow use of a single sequence for all my tables, in all schemas, I switched to following syntax. This allowed me to explicitly define the schema where sequence is located, without regard to what the current schema is.
Code:
<generator class="sequence">
  <param name="sequence">def_schema.hibernate_sequence</param>
</generator>


So your solution might look something like this:
Code:
<generator class="sequence">
  <param name="sequence">the_schema.*******.hibernate_unique_key</param>
</generator>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 07, 2004 2:04 am 
Newbie

Joined: Wed Sep 01, 2004 1:32 pm
Posts: 9
Location: (eastern) North Carolina
Maybe this is answer to your problem?

http://forum.hibernate.org/viewtopic.php?t=930789


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 07, 2004 2:17 am 
Beginner
Beginner

Joined: Tue Jun 22, 2004 7:50 am
Posts: 25
feester wrote:
Maybe this is answer to your problem?

http://forum.hibernate.org/viewtopic.php?t=930789


if you read the guy's post before replying you'd know it wasn't.

Quote:
It's the same error message as in
http://forum.hibernate.org/viewtopic.php?t=932807 this thread, but i've definitely already set the MySQLDialect. Any help that anyone can give as to what's causing this would be most appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 07, 2004 2:24 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Guess your id column isn't set to autoincrement.

See http://forum.hibernate.org/viewtopic.php?t=935050

HTH
Ernst


Top
 Profile  
 
 Post subject: hibernate_unique_key with generator native, huh???
PostPosted: Sun Jan 09, 2005 2:54 am 
Newbie

Joined: Sun Jan 09, 2005 2:30 am
Posts: 7
I get this error with the various versions of hibernate I've tried including 2.1.7c against my MySQL database on Windows XP (I've also tried various MySQL JDBC drivers from the latest version to a few versions back):

Table 'gsdata.hibernate_unique_key' doesn't exist"

My hbm.xml file explicitly has generator set to "native". Here's my table:

create table test (
id bigint not null auto_increment,
date_created datetime not null,
primary key (id)
);

here's my dialect:

hibernate.dialect = net.sf.hibernate.dialect.MySQLDialect

here's my Test.hbm.xml:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="gs.data.model.test.Test"
table="test">

<id
name="id"
column="id"
type="java.lang.Long"
unsaved-value="null">
<generator class="native">
</generator>
</id>

<property
name="dateCreated"
type="java.util.Date"
column="date_created"
not-null="true"
/>
</class>
</hibernate-mapping>

Any ideas what else I might try?


Top
 Profile  
 
 Post subject: Fixed it
PostPosted: Sun Jan 09, 2005 3:19 am 
Newbie

Joined: Sun Jan 09, 2005 2:30 am
Posts: 7
Fixed it. It turns out that indeed my dialect was not set properly. I was using Spring hibernate support and Spring wasn't properly picking up the dialect from my database.properties file due to a typo. Once I set the hibernate debug level to INFO I could see that the Dialect was set to a generic dialect.

In retrospect it might be nice to have Hibernate log a WARN if a user does not specify a dialect unless there are cases I'm not aware of where a user would want hibernate to have a default dialect.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 09, 2005 9:36 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The generic dialect executes ANSI SQL, which is a good thing.


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