O'Reilly logo

Mastering Hibernate by Ramin Rad

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Envers

Hibernate, since version 4, fully supports entity versioning, and it's called envers. This is very useful for keeping track of changes to each audited entity. In this section, you will see how to configure envers, choose the right strategy for entity auditing, and handle associated entities.

Configuration

The first thing you need to do is to add the appropriate JAR and class path to your project. Hibernate envers are packaged separately, so you'll have to add the Maven dependency:

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-envers</artifactId>
  <version>${envers-version}</version>
</dependency>

Once you have resolved the jar dependency, you could simply add the @Audited annotation to the entity that you wish to track: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required