Problem set-up: {code:java} @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 } {code} }
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.
{code:java} select element0_.id as id1_0_, element0_.version as version2_0_ from Element element0_ where ? in ( lists1_.id ) {code}
org.hibernate.exception.SQLGrammarException: could not prepare statement javax.persistence.PersistenceException at org.hibernate. jpa internal . spi ExceptionConverterImpl . AbstractEntityManagerImpl. convert( AbstractEntityManagerImpl ExceptionConverterImpl .java: 1692 154 ) at org.hibernate. jpa internal . spi ExceptionConverterImpl . AbstractEntityManagerImpl. convert( AbstractEntityManagerImpl ExceptionConverterImpl .java: 1602 181 ) at org.hibernate. jpa query .internal. QueryImpl AbstractProducedQuery . list(AbstractProducedQuery.java:1514) at org.hibernate.query.Query. getResultList( QueryImpl Query .java: 492 135 ) at com.gridapp.JPAUnitTestCase. testSaveElementFacilities hhh12936Test (JPAUnitTestCase.java: 48 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: 109 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: 1929 1984 ) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java: 1898 1914 ) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java: 1876 1892 ) at org.hibernate.loader.Loader.doQuery(Loader.java: 919 937 ) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java: 336 340 ) at org.hibernate.loader.Loader.doList(Loader.java: 2617 2689 ) at org.hibernate.loader.Loader.doList(Loader.java: 2600 2672 ) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java: 2429 2506 ) at org.hibernate.loader.Loader.list(Loader.java: 2424 2501 ) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java: 501 504 ) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java: 371 395 ) at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java: 216 220 ) at org.hibernate.internal.SessionImpl.list(SessionImpl.java: 1326 1508 ) at org.hibernate. query. internal. QueryImpl AbstractProducedQuery . list doList ( QueryImpl AbstractProducedQuery .java: 87 1537 ) at org.hibernate. jpa query .internal. QueryImpl AbstractProducedQuery .list( QueryImpl AbstractProducedQuery .java: 606 1505 ) at org . hibernate . jpa . internal.QueryImpl.getResultList(QueryImpl.java:483) ... 32 33 more Caused by: org.h2.jdbc.JdbcSQLException: Feld " FACILITIES1_ LISTS1_ .ID" nicht gefunden Column " FACILITIES1_ LISTS1_ .ID" not found; SQL statement: select element0_.id as id1_0_, element0_.version as version2_0_ , element0_.name as name3_0_ from Element element0_ where ? in ( facilities1_ 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
|
|