Lets assume the following mapping: {code} @Entity @Audited public class PersonDocument implements Serializable { @Id @ManyToOne(optional = false) private Person person; @Id @ManyToOne(optional = false) private Document document; } {code} Unfortunately when using the above entity to locate revisions using the following query: {code} auditReader.createQuery().forRevisionsOfEntity( PersonDocument.class, false, true ) .add( AuditEntity.relatedId( "person" ).eq( 42 ) ) .addOrder( AuditEntity.revisionNumber().desc() ); {code} Hibernate Envers will generate the following exception: {noformat} org.hibernate.envers.exception.AuditException: This criterion can only be used on a property that is a relation to another property.
at org.hibernate.envers.query.criteria.internal.RelatedAuditEqualityExpression.addToQuery(RelatedAuditEqualityExpression.java:51) at org.hibernate.envers.query.criteria.internal.AbstractAtomicExpression.addToQuery(AbstractAtomicExpression.java:48) at org.hibernate.envers.query.criteria.internal.RelatedAuditEqualityExpression.addToQuery(RelatedAuditEqualityExpression.java:22) at org.hibernate.envers.query.internal.impl.RevisionsOfEntityQuery.list(RevisionsOfEntityQuery.java:94) at org.hibernate.envers.query.internal.impl.AbstractAuditQuery.getResultList(AbstractAuditQuery.java:107) {noformat} The reason this fails is because the mapping configuration for the audited entity does not register relation mappings for properties annotated with {{@Id}}. |
|