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

Hibernate JIRA | Peter | 2 years ago
  1. 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
  2. 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
  3. 0

    [aerogear-dev] use oracle database

    jboss.org | 1 year ago
    org.hibernate.exception.SQLGrammarException: could not extract ResultSet* * 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.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:88)
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    HsqlException: unexpected token: SELECT

    hsqldb | 1 year ago | t0m45
    org.hibernate.exception.SQLGrammarException: could not prepare statement
  6. 0

    Org.hibernate.exception.SQLGrammarException: could not prepare statement - scriptscoop.com

    scriptscoop.com | 1 year ago
    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
      Loader.doQuery
      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:124)
      4. org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:193)
      5. org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:157)
      6. org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1881)
      7. org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1858)
      8. org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838)
      9. org.hibernate.loader.Loader.doQuery(Loader.java:906)
      9 frames