-->
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: Invalid sql generated for Mysql.
PostPosted: Wed Apr 19, 2006 3:37 pm 
Newbie

Joined: Wed Apr 19, 2006 3:10 pm
Posts: 2
Summary:
Executed sql appears to be invalid for Mysql.

Hibernate version:
3.1

Mapping documents:


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>

    <class name="events.Event" table="EVENTS">
        <id name="id" column="EVENT_ID">
            <generator class="increment"/>
        </id>
        <property name="date" type="timestamp" column="EVENT_DATE"/>
        <property name="title"/>

        <set name="participants" table="PERSON_EVENT" inverse="true">
            <key column="EVENT_ID"/>
            <many-to-many column="PERSON_ID" class="events.Person"/>
        </set>

    </class>
</hibernate-mapping>


Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!--For Hibernate's configuration, we can use a simple hibernate.properties file,
  a slightly more sophisticated hibernate.cfg.xml file, or even complete
  programmatic setup. Most users prefer the XML configuration file:
 
  Copy this file into the source directory,
  so it will end up in the root of the classpath.
  Hibernate automatically looks for a file called hibernate.cfg.xml
  in the root of the classpath, on startup.
-->

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql:///test</property>
        <property name="connection.username">belfers</property>
        <property name="connection.password"></property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.HSQLDialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">create</property>

        <mapping resource="com/examples/hibernate/Event.hbm.xml"/>
        <mapping resource="com/examples/hibernate/Person.hbm.xml"/>

    </session-factory>

</hibernate-configuration>


Code between sessionFactory.openSession() and session.close():
N/A

Full stack trace of any exception that occurs:

Code:
[java] 14:02:58,462 DEBUG SchemaExport:301 - drop table PERSON_EMAIL_ADDR if exists
     [java] 14:02:58,462 DEBUG SchemaExport:286 - Unsuccessful: drop table PERSON_EMAIL_ADDR if exists
     [java] 14:02:58,472 DEBUG SchemaExport:287 - 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 'if exists' at line 1



Name and version of the database you are using:

Mysql 4.1 and tried 5.0

The generated SQL (show_sql=true):

Code:
drop table EVENTS if exists


Should be
Quote:
drop table if exists EVENTS


Debug level Hibernate log excerpt:



Code:
[java] 14:02:58,442 DEBUG SchemaExport:301 - drop table EVENTS if exists
     [java] 14:02:58,452 DEBUG SchemaExport:286 - Unsuccessful: drop table EVENTS if exists
     [java] 14:02:58,452 DEBUG SchemaExport:287 - 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 'if exists' at line 1
     [java] 14:02:58,452 DEBUG SchemaExport:301 - drop table PERSON if exists
     [java] 14:02:58,462 DEBUG SchemaExport:286 - Unsuccessful: drop table PERSON if exists
     [java] 14:02:58,462 DEBUG SchemaExport:287 - 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 'if exists' at line 1
     [java] 14:02:58,462 DEBUG SchemaExport:301 - drop table PERSON_EMAIL_ADDR if exists
     [java] 14:02:58,462 DEBUG SchemaExport:286 - Unsuccessful: drop table PERSON_EMAIL_ADDR if exists
     [java] 14:02:58,472 DEBUG SchemaExport:287 - 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 'if exists' at line 1
     [java] 14:02:58,482 DEBUG SchemaExport:301 - drop table PERSON_EVENT if exists
     [java] 14:02:58,482 DEBUG SchemaExport:286 - Unsuccessful: drop table PERSON_EVENT if exists
     [java] 14:02:58,482 DEBUG SchemaExport:287 - 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 'if exists' at line 1
     [java] 14:02:58,482 DEBUG SchemaExport:301 - create table EVENTS (EVENT_ID bigint generated by default as identity (start with 1), EVENT_DATE timestamp, title varchar(255), primary key (EVENT_ID))
     [java] 14:02:58,502 ERROR SchemaExport:272 - Unsuccessful: create table EVENTS (EVENT_ID bigint generated by default as identity (start with 1), EVENT_DATE timestamp, title varchar(255), primary key (EVENT_ID))
     [java] 14:02:58,512 ERROR SchemaExport:273 - 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 'generated by default as identity (start with 1), EVENT_DATE timestamp, title var' at line 1


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 19, 2006 7:05 pm 
Beginner
Beginner

Joined: Mon Nov 29, 2004 2:26 pm
Posts: 28
You are using the wrong dialect for MySQL. Change the line:

Code:
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>


to

Code:
<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>


Top
 Profile  
 
 Post subject: Good catch.
PostPosted: Wed Apr 19, 2006 10:55 pm 
Newbie

Joined: Wed Apr 19, 2006 3:10 pm
Posts: 2
From one newbie to another, NICE CATCH!!! Credit granted!


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.