I using Hibernate Envers for auditing and have an issue with composite primary keys. I have many to many entities with composite primary key based on the relating properties. The construct is like following:
@Entity
@Audited
@Table(indexes = { @Index(columnList = "person_id"),
@Index(columnList = "document_id") })
public class PersonDocument implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@ManyToOne(optional = false, fetch = FetchType.EAGER)
private Document document;
@Id
@ManyToOne(optional = false, fetch = FetchType.EAGER)
private Person person;
The relation is not bi-directional annotated. The primary key is correct used in the audited tables, like the docu of envers describes it.
But now I wan't all revisions that relates to person. With following:
final AuditQuery query = AuditReaderFactory.get(entityManager)
.createQuery().forRevisionsOfEntity(PersonDocument.class, false, true)
.add(AuditEntity.relatedId("person").eq("12"))
.addOrder(AuditEntity.revisionNumber().desc());
Then I get following error:
This criterion can only be used on a property that is a relation to another property.
If I use a non composite primary key then it runs without problems, but with I get the error. Has anyone an Idea? The migration of the data from composite primary key to an extra primary key for many to many entity is not so easy.
I use Hibernate version 4.3.11
Best regards