Create A Custom Revision Entity
Create A Custom Revision Entity
www.thoughts-on-java.org
Hibernate Envers – Extend the standard revision
In this example, I extend the DefaultRevisionEntity because I just
want to store an additional userName attribute for each revision. I
also reference my implementation of the RevisionListener interface
in the @RevisionEntity annotation.
@Entity
@RevisionEntity(MyRevisionListener.class)
public class MyRevision extends DefaultRevisionEntity {
private String userName;
Implement a RevisionListener
The RevisionListener tells Hibernate Envers how to set the attributes
of the revision entity.
You can see an example of it in the following code snippet. You just
need to implement the newRevision(Object revisionEntity) method
which gets the newly instantiated revision entity as a parameter. The
only thing you have to do is to set the additional attributes. In this
example, I just need to set the userName attribute.
www.thoughts-on-java.org
Hibernate Envers – Extend the standard revision
…
}
AuditQuery q =
auditReader.createQuery().forRevisionsOfEntity(Book.class,
false, true);
q.addProjection(AuditEntity.revisionNumber());
q.add(AuditEntity.revisionProperty(“userName”).eq(“User
1”));
List<Number> revisionNumbers = q.getResultList();
www.thoughts-on-java.org