org.hibernate.exception.SQLGrammarException: could not prepare statement

Hibernate JIRA | Scott Marlow | 3 years ago
  1. 0

    {quote} org.hibernate.exception.SQLGrammarException: could not prepare statement at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:188) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareStatement(StatementPreparerImpl.java:91) at org.hibernate.procedure.internal.ProcedureCallImpl.buildOutputs(ProcedureCallImpl.java:299) at org.hibernate.procedure.internal.ProcedureCallImpl.getResult(ProcedureCallImpl.java:270) at org.hibernate.jpa.internal.StoredProcedureQueryImpl.outputs(StoredProcedureQueryImpl.java:177) at org.hibernate.jpa.internal.StoredProcedureQueryImpl.execute(StoredProcedureQueryImpl.java:194) {quote} StoredProcedureQueryImpl probably needs something like: {code} catch ( HibernateException he) { entityManager().throwPersistenceException( he ); } {code} {quote} 3.10.7 Query Execution ... Runtime exceptions other than the NoResultException, NonUniqueResultException, QueryTimeoutException, and LockTimeoutException thrown by the methods of the Query, TypedQuery, and StoredProcedureQuery interfaces other than those methods specified below cause the current transaction to be marked for rollback if the persistence context is joined to the transaction. On database platforms on which a query timeout causes transaction rollback, the persistence provider must throw the PersistenceException instead of the QueryTimeoutException. Runtime exceptions thrown by the following methods of the Query, TypedQuery, and StoredProcedureQuery interfaces do not cause the current transaction to be marked for rollback: getParameters, getParameter, getParameterValue, getOutputParameterValue, getLockMode. Runtime exceptions thrown by the methods of the Tuple, TupleElement, and Parameter interfaces do not cause the current transaction to be marked for rollback {quote}

    Hibernate JIRA | 3 years ago | Scott Marlow
    org.hibernate.exception.SQLGrammarException: could not prepare statement
  2. 0

    {quote} org.hibernate.exception.SQLGrammarException: could not prepare statement at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:188) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareStatement(StatementPreparerImpl.java:91) at org.hibernate.procedure.internal.ProcedureCallImpl.buildOutputs(ProcedureCallImpl.java:299) at org.hibernate.procedure.internal.ProcedureCallImpl.getResult(ProcedureCallImpl.java:270) at org.hibernate.jpa.internal.StoredProcedureQueryImpl.outputs(StoredProcedureQueryImpl.java:177) at org.hibernate.jpa.internal.StoredProcedureQueryImpl.execute(StoredProcedureQueryImpl.java:194) {quote} StoredProcedureQueryImpl probably needs something like: {code} catch ( HibernateException he) { entityManager().throwPersistenceException( he ); } {code} {quote} 3.10.7 Query Execution ... Runtime exceptions other than the NoResultException, NonUniqueResultException, QueryTimeoutException, and LockTimeoutException thrown by the methods of the Query, TypedQuery, and StoredProcedureQuery interfaces other than those methods specified below cause the current transaction to be marked for rollback if the persistence context is joined to the transaction. On database platforms on which a query timeout causes transaction rollback, the persistence provider must throw the PersistenceException instead of the QueryTimeoutException. Runtime exceptions thrown by the following methods of the Query, TypedQuery, and StoredProcedureQuery interfaces do not cause the current transaction to be marked for rollback: getParameters, getParameter, getParameterValue, getOutputParameterValue, getLockMode. Runtime exceptions thrown by the methods of the Tuple, TupleElement, and Parameter interfaces do not cause the current transaction to be marked for rollback {quote}

    Hibernate JIRA | 3 years ago | Scott Marlow
    org.hibernate.exception.SQLGrammarException: could not prepare statement
  3. 0

    HsqlException: unexpected token: SELECT

    hsqldb | 1 year ago | t0m45
    org.hibernate.exception.SQLGrammarException: could not prepare statement
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    InvalidDataAccessResourceUsage Exception in spring application test

    Stack Overflow | 10 hours ago | karan
    org.hibernate.exception.SQLGrammarException: could not prepare statement
  6. 0

    I've updated from Hibernate 4.1.7 to Hibernate 4.3. I'm using hsqldb 2.3.2 and I'm encountering an issue with a joined inheritance strategy and a DiscriminatorValue annotation. Hibernate appears to be generating invalid SQL (not quoting a referenced DiscriminatorValue in a query). Code that worked in 4.1.7: {code} criteria.add(Restrictions.eq("class", MyChildObject1.class)); {code} Now causes the following exception: {code} Hibernate: insert into MyBaseObject (id, DTYPE) values (default, 'one') Hibernate: insert into MyChildObject1 (id) values (?) Hibernate: insert into MyBaseObject (id, DTYPE) values (default, 'two') Hibernate: insert into MyChildObject2 (id) values (?) Hibernate: select this_.id as id2_0_0_, this_.DTYPE as DTYPE1_0_0_ from MyBaseObject this_ left outer join MyChildObject1 this_1_ on this_.id=this_1_.id left outer join MyChildObject2 this_2_ on this_.id=this_2_.id where case when this_1_.id is not null then one when this_2_.id is not null then two when this_.id is not null then 'MyBaseObject' end=? and (this_.id=? or this_.id=?) limit ? org.hibernate.exception.SQLGrammarException: could not prepare statement at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:193) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:157) at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1881) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1858) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838) at org.hibernate.loader.Loader.doQuery(Loader.java:906) ... Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: ONE at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source) at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:159) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:183) ... 50 more Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: ONE {code} MyBaseObject.java: {code} @Entity @Inheritance(strategy = InheritanceType.JOINED) @DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING) abstract class MyBaseObject { @Id @GeneratedValue(strategy = GenerationType.AUTO) public Long id; @Override public String toString() { return getClass().getSimpleName() + "{" + "id=" + id + '}'; } } {code} MyChildObject1.java: {code} @Entity @DiscriminatorValue("one") class MyChildObject1 extends MyBaseObject { } {code} MyChildObject2.java: {code} @Entity @DiscriminatorValue("two") class MyChildObject2 extends MyBaseObject { } {code}

    Hibernate JIRA | 2 years ago | Peter
    org.hibernate.exception.SQLGrammarException: could not prepare statement

    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. org.hibernate.exception.SQLGrammarException

      could not prepare statement

      at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert()
    2. Hibernate
      StatementPreparerImpl.prepareStatement
      1. org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82)
      2. org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
      3. org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
      4. org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:188)
      5. org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareStatement(StatementPreparerImpl.java:91)
      5 frames
    3. org.hibernate.procedure
      ProcedureCallImpl.getResult
      1. org.hibernate.procedure.internal.ProcedureCallImpl.buildOutputs(ProcedureCallImpl.java:299)
      2. org.hibernate.procedure.internal.ProcedureCallImpl.getResult(ProcedureCallImpl.java:270)
      2 frames
    4. org.hibernate.jpa
      StoredProcedureQueryImpl.execute
      1. org.hibernate.jpa.internal.StoredProcedureQueryImpl.outputs(StoredProcedureQueryImpl.java:177)
      2. org.hibernate.jpa.internal.StoredProcedureQueryImpl.execute(StoredProcedureQueryImpl.java:194)
      2 frames