org.hibernate.exception.SQLGrammarException: could not execute query

Hibernate JIRA | Rupesh Kumar | 8 years ago
  1. 0

    Usually when you have the table name with space in its name, you need to escape it while using it in the hbm file and that works. But if you have a property with formula that uses the same table, calling this code below it throws up error : org.hibernate.exception.SQLGrammarException Query query = session.createQuery("from tablewithspace"); List list = query.list(); tablewithspace.hbm.xml ------------------------------------ <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="tablewithspace" entityname="tablewithspace" table="[table with space]"> <id name="id" column="id" length="10" type="int"/> <property name="formulacol" formula="(select count(*) from [table with space])" type="string"/> <property name="name" column="name" length="50" type="string"/> </class> </hibernate-mapping> ----------------------------------- The stackstrace is org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.loader.Loader.doList(Loader.java:2231) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125) at org.hibernate.loader.Loader.list(Loader.java:2120) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) Caused by: java.sql.SQLException: [Macromedia][SQLServer JDBC Driver][SQLServer]Invalid object name 'ctablewith0_.table with space'. at macromedia.jdbc.base.BaseExceptions.createException(Unknown Source) at macromedia.jdbc.base.BaseExceptions.getException(Unknown Source) at macromedia.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source) at macromedia.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source) at macromedia.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source) at macromedia.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source) at macromedia.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source) at macromedia.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source) at macromedia.jdbc.base.BaseStatement.postImplExecute(Unknown Source) at macromedia.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source) at macromedia.jdbc.base.BaseStatement.commonExecute(Unknown Source) at macromedia.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source) at macromedia.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source) at macromedia.jdbc.base.BasePreparedStatementPoolable.executeQuery(Unknown Source) at coldfusion.server.j2ee.sql.JRunPreparedStatement.executeQuery(JRunPreparedStatement.java:74) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208) at org.hibernate.loader.Loader.getResultSet(Loader.java:1808) at org.hibernate.loader.Loader.doQuery(Loader.java:697) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) at org.hibernate.loader.Loader.doList(Loader.java:2228) ... 40 more

    Hibernate JIRA | 8 years ago | Rupesh Kumar
    org.hibernate.exception.SQLGrammarException: could not execute query
  2. 0

    Usually when you have the table name with space in its name, you need to escape it while using it in the hbm file and that works. But if you have a property with formula that uses the same table, calling this code below it throws up error : org.hibernate.exception.SQLGrammarException Query query = session.createQuery("from tablewithspace"); List list = query.list(); tablewithspace.hbm.xml ------------------------------------ <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="tablewithspace" entityname="tablewithspace" table="[table with space]"> <id name="id" column="id" length="10" type="int"/> <property name="formulacol" formula="(select count(*) from [table with space])" type="string"/> <property name="name" column="name" length="50" type="string"/> </class> </hibernate-mapping> ----------------------------------- The stackstrace is org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.loader.Loader.doList(Loader.java:2231) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125) at org.hibernate.loader.Loader.list(Loader.java:2120) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) Caused by: java.sql.SQLException: [Macromedia][SQLServer JDBC Driver][SQLServer]Invalid object name 'ctablewith0_.table with space'. at macromedia.jdbc.base.BaseExceptions.createException(Unknown Source) at macromedia.jdbc.base.BaseExceptions.getException(Unknown Source) at macromedia.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source) at macromedia.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source) at macromedia.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source) at macromedia.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source) at macromedia.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source) at macromedia.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source) at macromedia.jdbc.base.BaseStatement.postImplExecute(Unknown Source) at macromedia.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source) at macromedia.jdbc.base.BaseStatement.commonExecute(Unknown Source) at macromedia.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source) at macromedia.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source) at macromedia.jdbc.base.BasePreparedStatementPoolable.executeQuery(Unknown Source) at coldfusion.server.j2ee.sql.JRunPreparedStatement.executeQuery(JRunPreparedStatement.java:74) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208) at org.hibernate.loader.Loader.getResultSet(Loader.java:1808) at org.hibernate.loader.Loader.doQuery(Loader.java:697) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) at org.hibernate.loader.Loader.doList(Loader.java:2228) ... 40 more

    Hibernate JIRA | 8 years ago | Rupesh Kumar
    org.hibernate.exception.SQLGrammarException: could not execute query
  3. 0

    Could not find prepared statement with handle

    theserverside.com | 11 months ago
    org.hibernate.exception.GenericJDBCException: could not execute query
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Could not find prepared statement with handle

    theserverside.com | 11 months ago
    org.hibernate.exception.GenericJDBCException: could not execute query
  6. 0

    galtres.foundation | 3 months ago
    java.sql.SQLException: [Macromedia][SQLServer JDBC Driver][SQLServer]Invalid column name 'ListOrder'.

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.sql.SQLException

      [Macromedia][SQLServer JDBC Driver][SQLServer]Invalid object name 'ctablewith0_.table with space'.

      at macromedia.jdbc.base.BaseExceptions.createException()
    2. macromedia.jdbc.base
      BaseExceptions.getException
      1. macromedia.jdbc.base.BaseExceptions.createException(Unknown Source)
      2. macromedia.jdbc.base.BaseExceptions.getException(Unknown Source)
      2 frames
    3. macromedia.jdbc.sqlserver
      SQLServerImplStatement.getNextResultType
      1. macromedia.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
      2. macromedia.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
      3. macromedia.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
      4. macromedia.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
      5. macromedia.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
      5 frames
    4. macromedia.jdbc.base
      BasePreparedStatementPoolable.executeQuery
      1. macromedia.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
      2. macromedia.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
      3. macromedia.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source)
      4. macromedia.jdbc.base.BaseStatement.commonExecute(Unknown Source)
      5. macromedia.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
      6. macromedia.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source)
      7. macromedia.jdbc.base.BasePreparedStatementPoolable.executeQuery(Unknown Source)
      7 frames
    5. coldfusion.server.j2ee
      JRunPreparedStatement.executeQuery
      1. coldfusion.server.j2ee.sql.JRunPreparedStatement.executeQuery(JRunPreparedStatement.java:74)
      1 frame
    6. Hibernate
      QueryLoader.list
      1. org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
      2. org.hibernate.loader.Loader.getResultSet(Loader.java:1808)
      3. org.hibernate.loader.Loader.doQuery(Loader.java:697)
      4. org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
      5. org.hibernate.loader.Loader.doList(Loader.java:2228)
      6. org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
      7. org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
      8. org.hibernate.loader.Loader.doList(Loader.java:2231)
      9. org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
      10. org.hibernate.loader.Loader.list(Loader.java:2120)
      11. org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
      11 frames
    7. Hibernate HQL/JP-QL Parser
      QueryTranslatorImpl.list
      1. org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361)
      1 frame
    8. Hibernate
      QueryImpl.list
      1. org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
      2. org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148)
      3. org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
      3 frames