-->
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.  [ 3 posts ] 
Author Message
 Post subject: SQLGrammarException / one-to-many
PostPosted: Thu Feb 19, 2009 8:19 am 
Newbie

Joined: Thu Feb 19, 2009 7:15 am
Posts: 11
Hi @ all,

I i've got a problem! I modelled a DB with Question (table) and their option(s) (table). The tables should have a 0..* relation, meaning one question can have zero or more options, but one option belongs to only one question.

There for I created two mapping files:
question.hbm.xml:

Code:
<?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 package="core">
  <class name="Question" table="Frage">
     <id name="id" column="ID">
        <generator class="increment"></generator>
     </id>
     <property name="question" column="Frage"></property>
     <property name="answerClass" column="AntwortKlasse"></property>
     <property name="evaluationClass" column="AuswertungsKlasse"></property>
     <property name="obligation" column="Pflicht"></property>
     <property name="time" column="Zeit"></property>
     <property name="order" column="Reihenfolge"></property>
     <property name="hint" column="Hinweis"></property>
     <property name="groupID" column="GruppenID"></property>
     <set name="options" lazy="false" cascade="all">
        <key column="FrageID"></key>
        <one-to-many class="Option"></one-to-many>
     </set>
  </class>
</hibernate-mapping>


option.hbm.xml:

Code:
<?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 package="core">
  <class name="Option" table="Option">
     <id name="id" column="ID">
        <generator class="increment"></generator>
     </id>
     <property name="code" column="Code"></property>
     <property name="option" column="Option"></property>
     <property name="questionID" column="FrageID"></property>
  </class>
</hibernate-mapping>



I did not forget to include these files in the hibernate.hbm.xml!
So the Problem is this exception, when I want to store my question object:
WARN - JDBCExceptionReporter - SQL Error: 1064, SQLState: 42000
ERROR - JDBCExceptionReporter - 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 'Option' at line 1
org.hibernate.exception.SQLGrammarException: could not fetch initial value for increment generator

It would be sooo nice, if anyone could help me!!!!

With best regards
Andy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2009 8:27 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Option is reserved keyword in MySQL. When you use it as table name and column name, you should enclose it with backticks.
Code:
<class name="Option" table="`Option`">
...
  <property name="option" column="`Option`"></property>
...
</class>


Top
 Profile  
 
 Post subject: Yeah!
PostPosted: Thu Feb 19, 2009 8:34 am 
Newbie

Joined: Thu Feb 19, 2009 7:15 am
Posts: 11
you are my personal hero for today! Thanks a lot! It helped!!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.