org.hibernate.exception.SQLGrammarException

If you like a tip written by other Samebug users, mark is as helpful! Marks help our algorithm provide you better solutions and also help other users.
tip

Check if you're not creating unused SQL entities, as it might cause this exception.


rafael

You have a different solution? A short tip here would help you and many other users who saw this issue last week.

  • Doing a batch update such as {{update versioned Animal set weight = 69 where weight = 0}} generates a SQLGrammarException. {code} org.hibernate.exception.SQLGrammarException: could not prepare statement at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123) 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.hql.spi.TableBasedUpdateHandlerImpl.execute(TableBasedUpdateHandlerImpl.java:163) at org.hibernate.hql.internal.ast.exec.MultiTableUpdateExecutor.execute(MultiTableUpdateExecutor.java:65) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:415) at org.hibernate.engine.query.spi.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:282) at org.hibernate.internal.SessionImpl.executeUpdate(SessionImpl.java:1290) at org.hibernate.internal.QueryImpl.executeUpdate(QueryImpl.java:116) at org.hibernate.test.batch.joinedInheritence.BatchVersionedUpdateOfJoinedHierarchyTest.testUpdateVersionedWithWhereClause(BatchVersionedUpdateOfJoinedHierarchyTest.java:42) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:63) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30) at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:62) Caused by: org.h2.jdbc.JdbcSQLException: Table "ANIMAL0_" not found; SQL statement: update Animal set animal0_.version=animal0_.version+1, weight=69 where (id) IN (select id from HT_Animal) [42102-145] at org.h2.message.DbException.getJdbcSQLException(DbException.java:327) at org.h2.message.DbException.get(DbException.java:167) at org.h2.message.DbException.get(DbException.java:144) at org.h2.command.Parser.readTableColumn(Parser.java:632) at org.h2.command.Parser.parseUpdate(Parser.java:664) at org.h2.command.Parser.parsePrepared(Parser.java:413) at org.h2.command.Parser.parse(Parser.java:274) at org.h2.command.Parser.parse(Parser.java:246) at org.h2.command.Parser.prepare(Parser.java:200) at org.h2.command.Parser.prepareCommand(Parser.java:213) at org.h2.engine.Session.prepareLocal(Session.java:423) at org.h2.engine.Session.prepareCommand(Session.java:373) at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1056) at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:71) at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:233) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$1.doPrepare(StatementPreparerImpl.java:98) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:182) ... 20 more {code}
    via by Anders Wallgren,
  • Doing a batch update such as {{update versioned Animal set weight = 69 where weight = 0}} generates a SQLGrammarException. {code} org.hibernate.exception.SQLGrammarException: could not prepare statement at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123) 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.hql.spi.TableBasedUpdateHandlerImpl.execute(TableBasedUpdateHandlerImpl.java:163) at org.hibernate.hql.internal.ast.exec.MultiTableUpdateExecutor.execute(MultiTableUpdateExecutor.java:65) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:415) at org.hibernate.engine.query.spi.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:282) at org.hibernate.internal.SessionImpl.executeUpdate(SessionImpl.java:1290) at org.hibernate.internal.QueryImpl.executeUpdate(QueryImpl.java:116) at org.hibernate.test.batch.joinedInheritence.BatchVersionedUpdateOfJoinedHierarchyTest.testUpdateVersionedWithWhereClause(BatchVersionedUpdateOfJoinedHierarchyTest.java:42) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:63) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30) at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:62) Caused by: org.h2.jdbc.JdbcSQLException: Table "ANIMAL0_" not found; SQL statement: update Animal set animal0_.version=animal0_.version+1, weight=69 where (id) IN (select id from HT_Animal) [42102-145] at org.h2.message.DbException.getJdbcSQLException(DbException.java:327) at org.h2.message.DbException.get(DbException.java:167) at org.h2.message.DbException.get(DbException.java:144) at org.h2.command.Parser.readTableColumn(Parser.java:632) at org.h2.command.Parser.parseUpdate(Parser.java:664) at org.h2.command.Parser.parsePrepared(Parser.java:413) at org.h2.command.Parser.parse(Parser.java:274) at org.h2.command.Parser.parse(Parser.java:246) at org.h2.command.Parser.prepare(Parser.java:200) at org.h2.command.Parser.prepareCommand(Parser.java:213) at org.h2.engine.Session.prepareLocal(Session.java:423) at org.h2.engine.Session.prepareCommand(Session.java:373) at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1056) at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:71) at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:233) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$1.doPrepare(StatementPreparerImpl.java:98) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:182) ... 20 more {code}
    via by Anders Wallgren,
  • CachedRowSet Support
    via by da...@dandymadeproductions.com,
  • Method add of DyTasks fail
    via GitHub by oruam85
    ,
    • org.hibernate.exception.SQLGrammarException: could not prepare statement at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123) 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.hql.spi.TableBasedUpdateHandlerImpl.execute(TableBasedUpdateHandlerImpl.java:163) at org.hibernate.hql.internal.ast.exec.MultiTableUpdateExecutor.execute(MultiTableUpdateExecutor.java:65) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:415) at org.hibernate.engine.query.spi.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:282) at org.hibernate.internal.SessionImpl.executeUpdate(SessionImpl.java:1290) at org.hibernate.internal.QueryImpl.executeUpdate(QueryImpl.java:116) at org.hibernate.test.batch.joinedInheritence.BatchVersionedUpdateOfJoinedHierarchyTest.testUpdateVersionedWithWhereClause(BatchVersionedUpdateOfJoinedHierarchyTest.java:42) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:63) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30) at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:62) Caused by: org.h2.jdbc.JdbcSQLException: Table "ANIMAL0_" not found; SQL statement: update Animal set animal0_.version=animal0_.version+1, weight=69 where (id) IN (select id from HT_Animal) [42102-145] at org.h2.message.DbException.getJdbcSQLException(DbException.java:327) at org.h2.message.DbException.get(DbException.java:167) at org.h2.message.DbException.get(DbException.java:144) at org.h2.command.Parser.readTableColumn(Parser.java:632) at org.h2.command.Parser.parseUpdate(Parser.java:664) at org.h2.command.Parser.parsePrepared(Parser.java:413) at org.h2.command.Parser.parse(Parser.java:274) at org.h2.command.Parser.parse(Parser.java:246) at org.h2.command.Parser.prepare(Parser.java:200) at org.h2.command.Parser.prepareCommand(Parser.java:213) at org.h2.engine.Session.prepareLocal(Session.java:423) at org.h2.engine.Session.prepareCommand(Session.java:373) at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1056) at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:71) at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:233) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$1.doPrepare(StatementPreparerImpl.java:98) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:182) ... 20 more

    Users with the same issue

    batwalrus76
    4 times, last one,
    Handemelindo
    1 times, last one,
    rocday
    3 times, last one,
    Andreas Häber
    1 times, last one,
    osvzs
    1 times, last one,
    145 more bugmates