-->
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.  [ 2 posts ] 
Author Message
 Post subject: Wrong select syntax generated by Hibernate?
PostPosted: Wed Sep 29, 2010 3:41 pm 
Newbie

Joined: Mon Mar 10, 2008 11:55 am
Posts: 8
Hello,

I'm trying to connect to my MySQL 5.1 Database. It seems i've succedded except a SQL syntax errror generated by hibernate. I'm trying to execute a simple "findById".

I've tried MySQLDialect and MySQLInnoDBDialect but without success. Any ideas?

Code:
log4j:INFO Using URL [jar:file:/C:/workspace/lib/ressources/jboss/jbossall-client-3.2.1.jar!/log4j.properties] for automatic log4j configuration of repository named [default].
ERROR [main] (JDBCExceptionReporter.java:101) - 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 'desc as desc8_0_, country0_.code_used_iso_lang as code5_8_0_, country0_.code_iso' at line 1
ERROR [main] (CountryHome.java:114) - get failed
org.hibernate.exception.SQLGrammarException: could not load an entity: [ch.bemar.model.Country#1]
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.loader.Loader.loadEntity(Loader.java:1957)
    at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)
    at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76)
    at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3270)
    at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496)
    at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477)
    at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
    at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
    at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
    at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1080)
    at org.hibernate.impl.SessionImpl.get(SessionImpl.java:997)
    at ch.bemar.dao.CountryHome.findById(CountryHome.java:103)
    at ch.bemar.test.TestCountry.testFindByExample(TestCountry.java:14)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: com.mysql.jdbc.exceptions.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 'desc as desc8_0_, country0_.code_used_iso_lang as code5_8_0_, country0_.code_iso' at line 1
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1467)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1869)
    at org.hibernate.loader.Loader.doQuery(Loader.java:718)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
    at org.hibernate.loader.Loader.loadEntity(Loader.java:1953)
    ... 35 more


hibernate.cfg.xml
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">
<hibernate-configuration>
    <session-factory name="MyFactory">
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/creditfriend</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.default_catalog">creditfriend</property>
        <property name="hibernate.default_schema">creditfriend</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>

        <property name="hibernate.current_session_context_class">thread</property>

        <mapping resource="ch/bemar/hbm/Address.hbm.xml" />
        <mapping resource="ch/bemar/hbm/Authorisation.hbm.xml" />
        <mapping resource="ch/bemar/hbm/Car.hbm.xml" />
        <mapping resource="ch/bemar/hbm/Carbody.hbm.xml" />
        <mapping resource="ch/bemar/hbm/Carbrand.hbm.xml" />
        <mapping resource="ch/bemar/hbm/Company.hbm.xml" />
        <mapping resource="ch/bemar/hbm/Companytype.hbm.xml" />
        <mapping resource="ch/bemar/hbm/Contact.hbm.xml" />
        <mapping resource="ch/bemar/hbm/Country.hbm.xml" />
        <mapping resource="ch/bemar/hbm/DefaultLanguageIsoLang.hbm.xml" />
        <mapping resource="ch/bemar/hbm/Person.hbm.xml" />
        <mapping resource="ch/bemar/hbm/PetrolType.hbm.xml" />
        <mapping resource="ch/bemar/hbm/Salutation.hbm.xml" />
        <mapping resource="ch/bemar/hbm/User.hbm.xml" />
        <mapping resource="ch/bemar/hbm/Usergroup.hbm.xml" />

    </session-factory>
</hibernate-configuration>



Thank you for your help

Regards
Ben


Top
 Profile  
 
 Post subject: Re: Wrong select syntax generated by Hibernate?
PostPosted: Wed Sep 29, 2010 4:39 pm 
Newbie

Joined: Mon Mar 10, 2008 11:55 am
Posts: 8
bemar wrote:
[code]log4j:INFO Using URL [jar:file:/C:/workspace/lib/ressources/jboss/jbossall-client-3.2.1.jar!/log4j.properties] for automatic log4j configuration of repository named [default].
ERROR [main] (JDBCExceptionReporter.java:101) - 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 'desc as desc8_0_, country0_.code_used_iso_lang as code5_8_0_, country0_.code_iso' at line 1
ERROR [main] (CountryHome.java:114) - get failed


Got it. Had a field with name "desc" for the description field. "desc" is a reserved word in mysql and so it fails. Changed the field to "descr" and it worked.

Ben


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