Announcement Announcement Module
No announcement yet.
Error in the SQL syntax ?! Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error in the SQL syntax ?!


    I implemented a simple query with hibernate and I want to display some data in my console, but it says:
    This is my table:
    | neGroup_id | name | description |
    | 1 | MPR_NOR | A group with MPR_NOR NEs |
    | 2 | AWY KMP | A grou with AWY_KMP NEs |
    I use Reverse Engineering to get my files.
    NeGroup.hbm.xml :
        <class name="revEngMapping.NeGroup" table="neGroup">
            <id name="neGroupId" type="java.lang.Integer">
                <column name="neGroup_id" />
                <generator class="identity" />
            <property name="name" type="string">
                <column name="name" length="100" />
            <property name="description" type="string">
                <column name="description" />
            <set name="networkElements" table="neGroupAssociation" inverse="false" lazy="true" fetch="select">
                    <column name="neGroup_id" not-null="true" />
                <many-to-many entity-name="revEngMapping.NetworkElement">
                    <column name="networkElement_id" not-null="true" />
    Java file is so simple with just getters and setters, and finally my main:
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            Criteria crit = session.createCriteria(NeGroup.class);
            List resultList=crit.list();
            for(int i=0;i<resultList.size();i++)
          	  System.out.println(((NeGroup)resultList.get(i)).getName()+"  "+((NeGroup)resultList.get(i)).getDescription());
    neGroup_id is a composed primary key of another table that I don't mention in my main, Hope its not that causing the problem ..
    In my console:
    19:51:25,522 WARN JDBCExceptionReporter:233 - SQL Error: 1064, SQLState: 42000
    19:51:25,525 ERROR JDBCExceptionReporter:234 - 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 '.neGroup this_' at line 1
    Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
    at org.hibernate.exception.SQLStateConverter.convert(
    at org.hibernate.exception.JDBCExceptionHelper.conver t(
    at org.hibernate.loader.Loader.doList( 6)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(L
    at org.hibernate.loader.Loader.list(
    at org.hibernate.loader.criteria.CriteriaLoader.list(
    at org.hibernate.impl.SessionImpl.list(SessionImpl.ja va:1716)
    at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl. java:347)
    at main.main(
    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorEx ception: 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 '.neGroup this_' at line 1
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(
    at java.lang.reflect.Constructor.newInstance(Construc
    at com.mysql.jdbc.Util.handleNewInstance( 6)
    at com.mysql.jdbc.Util.getInstance(
    at com.mysql.jdbc.SQLError.createSQLException(SQLErro
    at com.mysql.jdbc.SQLError.createSQLException(SQLErro
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:3558)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:3490)
    at com.mysql.jdbc.MysqlIO.sendCommand( 59)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect( :2109)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionIm
    at com.mysql.jdbc.PreparedStatement.executeInternal(P
    at com.mysql.jdbc.PreparedStatement.executeQuery(Prep
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(Ab
    at org.hibernate.loader.Loader.getResultSet(Loader.ja va:1953)
    at org.hibernate.loader.Loader.doQuery( 2)
    at org.hibernate.loader.Loader.doQueryAndInitializeNo nLazyCollections(
    at org.hibernate.loader.Loader.doList( 3)
    ... 6 more
    Hope I can find a solution.

  • #2
    I got the problem, I logged the SQL query and fixed it, I was just mentioning the name of the database in the query which is wrong ..