An exception is thrown when querying for entities with Envers where an association is traversed and the target entity is mapped with inheritance strategy 'joined subclass'. This issue only occurs when using AuditStrategy 'ValidityAuditStrategy'. Consider the following example:
@Entity(name="EntityA")
@Audited
public class EntityA {
@Id
private Long id;
@OneToOne
private EntityC relationToC;
}
@Entity(name="EntityB)
@Audited
@Inheritance(strategy=InheritanceType.JOINED)
public class EntityB {
@Id
private Long id;
}
@Entity(name="EntityC")
@Audited
public class EntityC extends EntityB {
}
getAuditReader().createQuery()
.forEntitiesAtRevision(EntityA.class, 1)
.traverseRelation("relationToC", JoinType.INNER)
.getResultList();
The problem is that the REVEND property (in the ValidityAuditStrategy) is not available for the joined class (EntityC) because EntityC has InheritanceStrategy JOINED. Envers creates a JPQL query for its audit queries, so this issue exists in hibernate core. It seems that whenever an entity is joined with unrelated property join and that Entity has InheritanceStrategy JOINED, no properties of a superclass may be used in the query. I have created a simple example which reproduces this problem in hibernate-core:
@Entity(name="EntityA")
public class EntityA {
@Id
private Long id;
private String propA;
}
@Entity(name="EntityB)
@Inheritance(strategy=InheritanceType.JOINED)
public class EntityB {
@Id
private Long id;
private String propB;
}
@Entity(name="EntityC")
public class EntityC extends EntityB {
private String propC;
}
getEntityManager()
.createQuery("select a from EntityA a inner join EntityC c on a.propA=c.propC where c.propB='foo'")
.getResultList();
In this example the property 'propB' of EntityC is not available since it is defined on superclass EntityB. Here are the stack traces of the two examples: The Envers example:
The JPQL example:
|