[JIRA] (HHH-13956) Envers entities with @OneToMany relationshipd with @OrderBy fail to read in 5.4.14
by Alex Roytman (JIRA)
Alex Roytman ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMWQ1ZjI2NWM5... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-13956?atlOrigin=eyJpIjoiMWQ1Zj... ) HHH-13956 ( https://hibernate.atlassian.net/browse/HHH-13956?atlOrigin=eyJpIjoiMWQ1Zj... ) Envers entities with @OneToMany relationshipd with @OrderBy fail to read in 5.4.14 ( https://hibernate.atlassian.net/browse/HHH-13956?atlOrigin=eyJpIjoiMWQ1Zj... )
Issue Type: Bug Affects Versions: 5.4.14 Assignee: Chris Cranford ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) Components: hibernate-envers Created: 17/Apr/2020 12:42 PM Environment: JDK 1.8 Priority: Critical Reporter: Alex Roytman ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
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
for example
*Engagement *entity has
@OneToMany(mappedBy = "work" ,fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true )
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
// @OrderBy( "teamWorkRole,engagementTeamId" )
public List<EngagementTeam> getEngagementTeams() {
return this.engagementTeams;
}
Where
@Audited
@Entity
public class EngagementTeam {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ENGAGEMENT_ID" )
public Engagement getEngagement() {
return work;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "TEAM_WORK_ROLE" )
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
public TeamWorkRole getTeamWorkRole() {
return teamWorkRole;
}
}
reading it
with
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)
Thank you,
alex
( https://hibernate.atlassian.net/browse/HHH-13956#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-13956#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100124- sha1:93e2dd3 )
4 years, 9 months