Hibernate.orgCommunity Documentation

Chapter 5. Tutorial Using Envers

5.1. persistence.xml
5.2. The annotated entity Java class
5.3. Example code

This tutorial is located within the download bundle under envers and illustrates

This file was discussed in the JPA tutorial, and is largely the same here. The major difference is the set of properties defining listeners. Essentially this enables Envers to recieve notfications from Hibernate processing of certain events such as an entity being saved or updated.

Again, the entity is largely the same as seen in the JPA tutorial. The major difference to notice is the addition of the @org.hibernate.envers.Audited annotation which tells Envers to automatically track changes to this entity.

Again, this tutorial makes use of the JPA APIs. However, the code also makes a change to one of the entites and then uses the Envers API to pull back the initial revision (version) as well as the updated revision.

First an org.hibernate.envers.AuditReader is obtained from the org.hibernate.envers.AuditReaderFactory wrapping the javax.persistence.EntityManager.

Then the find method is used to retrieve specific revisions of the entity. The first call reads "find revision number 1 of Event with id 2". The second call reads "find revision number 2 of Event with id 2".