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: ...
Get Mastering Hibernate now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.