-->
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: Increment - ID - Exception
PostPosted: Thu Apr 14, 2011 3:01 am 
Newbie

Joined: Thu Mar 25, 2010 5:14 am
Posts: 8
I am trying to create a simple example for saving a object with two fields (MySQL 5) of which one is an ID. I defined the following in the HBM.XML
Code:
                 <id name="Index" type="long">
         <column name="INDEX" unique="true" length="20" />
         <generator class="increment" />
      </id>


and the corresponding SQL that is generated by the org.hibernate.dialect.HSQLDialect is

Code:
select
        max(INDEX)
    from
        table1


which does not runs successfully even in MySQL query browser. I am getting exception
Code:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INDEX)



I am not sure what is a miss here.

- Samarthya


Top
 Profile  
 
 Post subject: Re: Increment - ID - Exception
PostPosted: Thu Apr 14, 2011 3:22 am 
Newbie

Joined: Thu Mar 25, 2010 5:14 am
Posts: 8
When I debug and manually edit the query to
Code:
select
        max(table1.INDEX)
from
        table1


in IncrementGenerator class it works fine. What is it that I am doing wrong any idea anyone?


Top
 Profile  
 
 Post subject: Re: Increment - ID - Exception
PostPosted: Thu Apr 14, 2011 3:24 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
INDEX is a reserved keyword. If you want to use that as the column name, you need to quote with backticks it like this:

Code:
<column name="`INDEX`" ....


Top
 Profile  
 
 Post subject: Re: Increment - ID - Exception
PostPosted: Thu Apr 14, 2011 3:46 am 
Newbie

Joined: Thu Mar 25, 2010 5:14 am
Posts: 8
Thanks! it does works but when I try to insert some values
Code:
insert
    into
        table1
        (TIMESTAMP, "INDEX")
    values
        (?, ?)



I get the same exception

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"INDEX")


Top
 Profile  
 
 Post subject: Re: Increment - ID - Exception
PostPosted: Thu Apr 14, 2011 3:51 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
...SQL that is generated by the org.hibernate.dialect.HSQLDialect...


Quote:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException


Are you using HSQL or MySQL? With MySQL you should use one of the MySQL dialects.


Top
 Profile  
 
 Post subject: Re: Increment - ID - Exception
PostPosted: Thu Apr 14, 2011 4:16 am 
Newbie

Joined: Thu Mar 25, 2010 5:14 am
Posts: 8
I am using MySQL - Thanks for the tip though!


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.