org.hibernate.hql.internal.ast.InvalidWithClauseException: with-clause expressions did not reference from-clause element to which the with-clause was associated [select a from org.hibernate.test.hql.SimpleEntityWithAssociation as e LEFT JOIN e.associatedEntities as a WITH e.name=?]

Hibernate JIRA | Brett Meyer | 3 years ago
  1. 0

    Simple example: {code} public class SimpleEntityWithAssociation { ... private Set associatedEntities = new HashSet(); ... {code} {code} public class SimpleAssociatedEntity { ... private SimpleEntityWithAssociation owner; ... {code} "select a from SimpleEntityWithAssociation as e LEFT JOIN e.associatedEntities as a WITH e.name=?" {code} org.hibernate.hql.internal.ast.InvalidWithClauseException: with-clause expressions did not reference from-clause element to which the with-clause was associated [select a from org.hibernate.test.hql.SimpleEntityWithAssociation as e LEFT JOIN e.associatedEntities as a WITH e.name=?] at org.hibernate.hql.internal.ast.HqlSqlWalker.handleWithFragment(HqlSqlWalker.java:424) at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:399) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3779) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3565) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3443) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:706) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:562) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:263) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:191) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:143) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:119) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:87) at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:190) at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:300) at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:238) at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1779) at org.hibernate.test.hql.WithClauseTest.testWithJoinRHS(WithClauseTest.java:179) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) 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) {code}

    Hibernate JIRA | 3 years ago | Brett Meyer
    org.hibernate.hql.internal.ast.InvalidWithClauseException: with-clause expressions did not reference from-clause element to which the with-clause was associated [select a from org.hibernate.test.hql.SimpleEntityWithAssociation as e LEFT JOIN e.associatedEntities as a WITH e.name=?]
  2. 0

    Simple example: {code} public class SimpleEntityWithAssociation { ... private Set associatedEntities = new HashSet(); ... {code} {code} public class SimpleAssociatedEntity { ... private SimpleEntityWithAssociation owner; ... {code} "select a from SimpleEntityWithAssociation as e LEFT JOIN e.associatedEntities as a WITH e.name=?" {code} org.hibernate.hql.internal.ast.InvalidWithClauseException: with-clause expressions did not reference from-clause element to which the with-clause was associated [select a from org.hibernate.test.hql.SimpleEntityWithAssociation as e LEFT JOIN e.associatedEntities as a WITH e.name=?] at org.hibernate.hql.internal.ast.HqlSqlWalker.handleWithFragment(HqlSqlWalker.java:424) at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:399) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3779) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3565) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3443) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:706) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:562) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:263) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:191) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:143) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:119) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:87) at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:190) at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:300) at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:238) at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1779) at org.hibernate.test.hql.WithClauseTest.testWithJoinRHS(WithClauseTest.java:179) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) 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) {code}

    Hibernate JIRA | 3 years ago | Brett Meyer
    org.hibernate.hql.internal.ast.InvalidWithClauseException: with-clause expressions did not reference from-clause element to which the with-clause was associated [select a from org.hibernate.test.hql.SimpleEntityWithAssociation as e LEFT JOIN e.associatedEntities as a WITH e.name=?]
  3. 0

    An exception is thrown when an association of a superclass is traversed when the entity and its superclass are mapped with table-per-subclass mapping. Consider the following example: Entity B is a subclass of Entity A. Entity A has a relation to Entity C called 'relationToC'. A and B are mapped with table-per-subclass. When an Envers Query is created where Entity B is requested and the relation 'relationToC' is traversed, an exception is thrown when executing the query: {code:java} class A { C relationToC; } class B extends A { // mapped with table per subclass } class C { String foo; } AuditReader reader; reader.createQuery() .forEntitiesAtRevision(B.class, 42) .traverseRelation("associationToC",JoinType.INNER) .add(AuditEntity.property("foo").eq("bar")) .getResultList(); {code} This issue might be related to HHH-2772. There is no workaround for this issue. Exception stack trace: {code:java} java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.InvalidWithClauseException: with clause can only reference columns in the driving table [select e__ from example.domain.Option_AUD e__ inner join example.domain.AbstractAsset_AUD e1 on e__.underlying_id = e1.originalId.id where e__.originalId.rev.id <= :revision and e__.revtype <> :_p0 and (e__.revend.id > :revision or e__.revend is null) and (e__.name like :_p1 or e1.name like :_p2) and e1.originalId.rev.id <= :revision and (e1.revend.id > :revision or e1.revend is null)] at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:131) at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155) at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:162) at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:662) at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:102) at org.hibernate.envers.internal.tools.query.QueryBuilder.toQuery(QueryBuilder.java:248) at org.hibernate.envers.query.internal.impl.AbstractAuditQuery.buildQuery(AbstractAuditQuery.java:93) at org.hibernate.envers.query.internal.impl.EntitiesAtRevisionQuery.list(EntitiesAtRevisionQuery.java:121) at org.hibernate.envers.query.internal.impl.AbstractAuditQuery.getResultList(AbstractAuditQuery.java:107) at de.patronas.opus.persistence.impl.HistoricDAOImpl.getPageWithAst_aroundBody6(HistoricDAOImpl.java:351) at de.patronas.opus.persistence.impl.HistoricDAOImpl$AjcClosure7.run(HistoricDAOImpl.java:1) at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149) at de.patronas.opus.persistence.impl.permission.AccountSegmentPermissionFilter.filterResults(AccountSegmentPermissionFilter.java:39) at de.patronas.opus.persistence.impl.permission.AccountSegmentPermissionAspect.filterResults(AccountSegmentPermissionAspect.java:19) at de.patronas.opus.persistence.impl.HistoricDAOImpl.getPageWithAst(HistoricDAOImpl.java:321) at de.patronas.opus.persistence.integrationtest.paging.HistoricPagingAstTest.testGetHistoricPaging2(HistoricPagingAstTest.java:222) 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.rules.TestWatcher$1.evaluate(TestWatcher.java:55) at de.patronas.opus.persistence.impl.util.MockJNDIRule$1.evaluate(MockJNDIRule.java:50) at org.junit.rules.RunRules.evaluate(RunRules.java:20) 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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: org.hibernate.hql.internal.ast.InvalidWithClauseException: with clause can only reference columns in the driving table [select e__ from example.domain.Option_AUD e__ inner join example.domain.AbstractAsset_AUD e1 on e__.underlying_id = e1.originalId.id where e__.originalId.rev.id <= :revision and e__.revtype <> :_p0 and (e__.revend.id > :revision or e__.revend is null) and (e__.name like :_p1 or e1.name like :_p2) and e1.originalId.rev.id <= :revision and (e1.revend.id > :revision or e1.revend is null)] at org.hibernate.hql.internal.ast.HqlSqlWalker$WithClauseVisitor.visit(HqlSqlWalker.java:571) at org.hibernate.hql.internal.ast.util.NodeTraverser.visitDepthFirst(NodeTraverser.java:60) at org.hibernate.hql.internal.ast.util.NodeTraverser.traverseDepthFirst(NodeTraverser.java:49) at org.hibernate.hql.internal.ast.HqlSqlWalker.handleWithFragment(HqlSqlWalker.java:497) at org.hibernate.hql.internal.ast.HqlSqlWalker.createEntityJoin(HqlSqlWalker.java:477) at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:377) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3915) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3701) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3579) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:718) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:574) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:311) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:259) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:262) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:190) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:142) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:115) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:77) at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:153) at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:545) at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:654) {code}

    Hibernate JIRA | 1 week ago | Felix Feisst
    java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.InvalidWithClauseException: with clause can only reference columns in the driving table [select e__ from example.domain.Option_AUD e__ inner join example.domain.AbstractAsset_AUD e1 on e__.underlying_id = e1.originalId.id where e__.originalId.rev.id <= :revision and e__.revtype <> :_p0 and (e__.revend.id > :revision or e__.revend is null) and (e__.name like :_p1 or e1.name like :_p2) and e1.originalId.rev.id <= :revision and (e1.revend.id > :revision or e1.revend is null)]
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.hibernate.hql.internal.ast.InvalidWithClauseException

      with-clause expressions did not reference from-clause element to which the with-clause was associated [select a from org.hibernate.test.hql.SimpleEntityWithAssociation as e LEFT JOIN e.associatedEntities as a WITH e.name=?]

      at org.hibernate.hql.internal.ast.HqlSqlWalker.handleWithFragment()
    2. Hibernate
      SessionImpl.createQuery
      1. org.hibernate.hql.internal.ast.HqlSqlWalker.handleWithFragment(HqlSqlWalker.java:424)
      2. org.hibernate.hql.internal.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:399)
      3. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3779)
      4. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3565)
      5. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3443)
      6. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:706)
      7. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:562)
      8. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299)
      9. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247)
      10. org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:263)
      11. org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:191)
      12. org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:143)
      13. org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:119)
      14. org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:87)
      15. org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:190)
      16. org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:300)
      17. org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:238)
      18. org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1779)
      18 frames
    3. org.hibernate.test
      WithClauseTest.testWithJoinRHS
      1. org.hibernate.test.hql.WithClauseTest.testWithJoinRHS(WithClauseTest.java:179)
      1 frame
    4. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      4. java.lang.reflect.Method.invoke(Method.java:601)
      4 frames
    5. JUnit
      FrameworkMethod.invokeExplosively
      1. org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
      2. org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      3. org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
      3 frames
    6. A Hibernate O/RM Module
      ExtendedFrameworkMethod.invokeExplosively
      1. org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:63)
      1 frame
    7. JUnit
      FailOnTimeout$StatementThread.run
      1. org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      2. org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
      3. org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
      4. org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:62)
      4 frames