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

  • Error in the SQL syntax ?!

    Hi,

    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 :
    Code:
    <hibernate-mapping>
        <class name="revEngMapping.NeGroup" table="neGroup">
            <id name="neGroupId" type="java.lang.Integer">
                <column name="neGroup_id" />
                <generator class="identity" />
            </id>
            <property name="name" type="string">
                <column name="name" length="100" />
            </property>
            <property name="description" type="string">
                <column name="description" />
            </property>
            <set name="networkElements" table="neGroupAssociation" inverse="false" lazy="true" fetch="select">
                <key>
                    <column name="neGroup_id" not-null="true" />
                </key>
                <many-to-many entity-name="revEngMapping.NetworkElement">
                    <column name="networkElement_id" not-null="true" />
                </many-to-many>
            </set>
        </class>
    </hibernate-mapping>
    Java file is so simple with just getters and setters, and finally my main:
    Code:
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            session.beginTransaction();
            
            
            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());
            
            
            session.getTransaction().commit();
    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( SQLStateConverter.java:92)
    at org.hibernate.exception.JDBCExceptionHelper.conver t(JDBCExceptionHelper.java:66)
    at org.hibernate.loader.Loader.doList(Loader.java:253 6)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(L oader.java:2276)
    at org.hibernate.loader.Loader.list(Loader.java:2271)
    at org.hibernate.loader.criteria.CriteriaLoader.list( CriteriaLoader.java:119)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.ja va:1716)
    at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl. java:347)
    at main.main(main.java:38)
    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(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Construc tor.java:513)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:40 6)
    at com.mysql.jdbc.Util.getInstance(Util.java:381)
    at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:1030)
    at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:956)
    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(MysqlIO.java:19 59)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java :2109)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionIm pl.java:2643)
    at com.mysql.jdbc.PreparedStatement.executeInternal(P reparedStatement.java:2077)
    at com.mysql.jdbc.PreparedStatement.executeQuery(Prep aredStatement.java:2228)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(Ab stractBatcher.java:208)
    at org.hibernate.loader.Loader.getResultSet(Loader.ja va:1953)
    at org.hibernate.loader.Loader.doQuery(Loader.java:80 2)
    at org.hibernate.loader.Loader.doQueryAndInitializeNo nLazyCollections(Loader.java:274)
    at org.hibernate.loader.Loader.doList(Loader.java:253 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 ..

    Comment

    Working...
    X