Access Keys:
Skip to content (Access Key - 0)

Envers - Easy Entity Versioning

Abstract

The need for versioning of data comes up in many situations, for example if you want to maintain an audit log or if you write a wiki-type application. Envers is a library for JPA/Hibernate, which enables you to do just that: store and retrieve historical data, in a very easy way. It's usage is transparent to the programmer, and very non-intrusive. Code changes are minimal, and boil down to adding just one annotation to your entities: @Versioned. No additional actions are required from the programmer to write historical data, it is done automatically behind the scenes. Also, "latest" data can be accesed as always; querying, persisting, removing entities is done normally (using either the Session or EntityManager).

To read historical data, a clean and simple interface is available. For each successful transaction, in which versioned data is changed, a revision is created, similarly to a version control system like Subversion. This way, only data in "consistent" state is captured as a new revision. A very important feature of Envers is that apart from versioning basic data types, like strings, numbers, dates, etc, you can also version relations between entities. Thanks to that, it is possible to explore the data that the database contained at a given timestamp/revision with ease. It is also possible to query historical data - for example, to execute a query "at a given revision".

In the session, additionally to presenting Envers, I will show the most important versioning patterns, their difficulty level, for which use cases they are well suited, as well as their main advantages and disadvantages. As an example of solving a typical problem, I will demonstrate "bi-temporal" versioning and how a "structured wiki" can be implemented using Envers.

Project website: http://www.jboss.org/envers.

Speaker

Adaptavist Theme Builder Powered by Atlassian Confluence