A JBoss Project
Red Hat

Easy Entity Auditing/Versioning

From Hibernate 3.5, Envers is included as a Hibernate core module.

For downloads, please go to the Hibernate downloads page. Envers is also available in JBoss Maven repositories. 

Documentation is hosted on the Hibernate docs site.

This page won't be updated in the future. All new releases, documentation updates etc. will be done through the Hibernate site.

You can track Envers updates via the Envers blog.

by envers at Tue Oct 12 05:53:39 EDT 2010

Envers: Easy Entity Auditing

Envers Code Example
The Envers project aims to enable easy auditing/versioning of persistent classes. All that you have to do is annotate your persistent class or some of its properties, that you want to audit, with @Audited. For each audited entity, a table will be created, which will hold the history of changes made to the entity. You can then retrieve and query historical data without much effort.

 


Similarly to Subversion, Envers has a concept of revisions. Basically, one transaction is one revision (unless the transaction didn't modify any audited entities). As the revisions are global, having a revision number, you can query for various entities at that revision, retrieving a (partial) view of the database at that revision. You can find a revision number having a date, and the other way round, you can get the date at which a revision was commited.

Envers is a Hibernate core module and works with Hibernate and Hibernate Entity Manager (see hibernate.org). For the auditing to work properly, the entities must have immutable unique identifiers (primary keys). You can use Envers wherever Hibernate works: standalone, inside JBoss AS, with JBoss Seam or Spring.

Some of the features:
  • auditing of all mappings defined by the JPA specification
  • auditing of some Hibernate mappings, which extend JPA, like custom types and collections/maps of "simple" types (Strings, Integers, etc.) (see here for one exception)
  • logging data for each revision using a "revision entity"
  • querying historical data

For a quick tutorial on how to use Envers, see the Quick Start page.

On the downloads page, you'll find the jar with the library, the source code, as well as an Envers+Seam demo: a simple wiki application and bi-temporal versioning demo.

You can also try a console demo, which is a simple app where you can create, modify and view versions of two simple entities (Person and Address), and modify a one-to-many relation between them. By default it uses hsqldb, but you can overwrite the persistence.xml and check how it works with your database, see the structure of the generated tables etc.

 

Blog of Adam Warski

Java, Scala, programming, ...
MacWire 0.7: dynamically accessing the object graph
Jul 22, 2014 7:24 AM by Adam Warski
Making the Reactive Queue durable with Akka Persistence
Jul 3, 2014 8:17 AM by Adam Warski
Evaluating persistent, replicated message queues (updated w/ Kafka)
Jul 1, 2014 8:08 AM by Adam Warski
Benchmarking SQS
Jun 24, 2014 8:05 AM by Adam Warski
Cluster-wide Java/Scala application deployments with Docker, Chef and Amazon OpsWorks
Jun 12, 2014 7:50 AM by Adam Warski
View more blog of adam warski