We're updating the issue view to help you get more done. 

Envers Query API: Cannot traverse relation of superclass with table-per-subclass mapping

Description

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:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 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();

This issue might be related to HHH-2772.

There is no workaround for this issue.

Exception stack trace:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 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)

Environment

None

Status

Assignee

Chris Cranford

Reporter

Felix Feisst

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.2.4

Priority

Major