Migrating from Hibernate /Envers 4.3.8 to 5.4.14 one thing breaks consistently is reading an envers revision of my entity at specific revision where the entity has @OneToMany (bidirectional with mappedBy) with @OrderBy under any of the two conditions: 1. @OrderBy includes a ID of the "many" entity 2. @OrderBy includes a field of many entity which is itself a relation (@ManyToOne) it does not seem to matter if that field points to an audited entity or has targetAuditMode = RelationTargetAuditMode.NOT_AUDITED
Doing removing @OrderBy from @OneToMany or using any regular field (not matching conditions mentioned above) of the "many" entity works fine it just its ID and ManyToOne relationship fields that fail
AuditReader reader = AuditReaderFactory.get(getSession());
AuditQuery query = reader.createQuery().forEntitiesAtRevision(Engagement.class, revisionId);
query.add(AuditEntity.id().eq(engagementId));
Engagement eng = (Engagement) query.getSingleResult();
// reading content of eng.getEngagementTeams() will fail with the exception below
org.hibernate.QueryException: could not resolve property: teamWorkRole of: gov.gao.ems.model.engagement.EngagementTeam_AUD [select e__ from gov.gao.ems.model.engagement.EngagementTeam_AUD e__ where e__.work_engagementId = :work_engagementId and e__.originalId.REV.id = (select max(e2__.originalId.REV.id) from gov.gao.ems.model.engagement.EngagementTeam_AUD e2__ where e2__.originalId.REV.id <= :revision and e__.originalId.engagementTeamId = e2__.originalId.engagementTeamId) and REVTYPE != :delrevisiontype order by e__.teamWorkRole, e__.engagementTeamId]
at org.hibernate.QueryException.generateQueryException(QueryException.java:120)
at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:220)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:144)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:113)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:73)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:155)
at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:604)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:716)
... 8 more
Caused by: org.hibernate.QueryException: could not resolve property: teamWorkRole of: gov.gao.ems.model.engagement.EngagementTeam_AUD
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:73)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:67)
at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:2044)
at org.hibernate.hql.internal.ast.tree.FromElementType.getPropertyType(FromElementType.java:412)
at org.hibernate.hql.internal.ast.tree.FromElement.getPropertyType(FromElement.java:520)
at org.hibernate.hql.internal.ast.tree.DotNode.getDataType(DotNode.java:693)
at org.hibernate.hql.internal.ast.tree.DotNode.prepareLhs(DotNode.java:268)
at org.hibernate.hql.internal.ast.tree.DotNode.resolve(DotNode.java:208)
at org.hibernate.hql.internal.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:1053)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1303)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.orderExpr(HqlSqlBaseWalker.java:1887)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.orderExprs(HqlSqlBaseWalker.java:1681)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.orderClause(HqlSqlBaseWalker.java:1654)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:666)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:325)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:273)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:272)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:192)