Uploaded image for project: 'Hibernate ORM'
  1. HHH-12936

SQLGrammarException if entity field name is 'elements'

    Details

    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

      Problem set-up:

      @Entity
      public class Element {
          @ManyToMany
          private Set<List> lists = new HashSet<>();
          // getter/setter
      }
      @Entity
      public class List extends IdentifiedEntity
      {
          @ManyToMany(mappedBy = "lists")
          private Set<Element> elements = new HashSet<>();
          // getter/setter
      }
      

      }

      Problem execution:
      When executing following JPQL query "SELECT e FROM Element e WHERE :list MEMBER OF e.lists", I get following nonsense query and stack trace (happens also when writing query with Criteria).

      Problem diagnosis:
      When renaming the field 'elements' in class List, the bug disappears.

      select
              element0_.id as id1_0_,
              element0_.version as version2_0_ 
          from
              Element element0_ 
          where
              ? in (
                  lists1_.id
              )
      

      org.hibernate.exception.SQLGrammarException: could not prepare statement
      javax.persistence.PersistenceException
      at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)
      at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181)
      at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1514)
      at org.hibernate.query.Query.getResultList(Query.java:135)
      at com.gridapp.JPAUnitTestCase.hhh12936Test(JPAUnitTestCase.java:47)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
      at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
      at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
      at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
      at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
      at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
      at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
      Caused by: org.hibernate.exception.SQLGrammarException: could not prepare statement
      at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:106)
      at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
      at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:182)
      at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:148)
      at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1984)
      at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1914)
      at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1892)
      at org.hibernate.loader.Loader.doQuery(Loader.java:937)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:340)
      at org.hibernate.loader.Loader.doList(Loader.java:2689)
      at org.hibernate.loader.Loader.doList(Loader.java:2672)
      at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2506)
      at org.hibernate.loader.Loader.list(Loader.java:2501)
      at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:504)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:395)
      at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:220)
      at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1508)
      at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1537)
      at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1505)
      ... 33 more
      Caused by: org.h2.jdbc.JdbcSQLException: Feld "LISTS1_.ID" nicht gefunden
      Column "LISTS1_.ID" not found; SQL statement:
      select element0_.id as id1_0_, element0_.version as version2_0_ from Element element0_ where ? in (lists1_.id) [42122-176]
      at org.h2.message.DbException.getJdbcSQLException(DbException.java:344)
      at org.h2.message.DbException.get(DbException.java:178)
      at org.h2.message.DbException.get(DbException.java:154)
      at org.h2.expression.ExpressionColumn.optimize(ExpressionColumn.java:148)
      at org.h2.expression.ConditionIn.optimize(ConditionIn.java:91)
      at org.h2.command.dml.Select.prepare(Select.java:834)
      at org.h2.command.Parser.prepareCommand(Parser.java:248)
      at org.h2.engine.Session.prepareLocal(Session.java:442)
      at org.h2.engine.Session.prepareCommand(Session.java:384)
      at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1188)
      at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:73)
      at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:276)
      at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:146)
      at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:172)
      ... 49 more

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: