Questions tagged [hibernate-envers]

Hibernate Envers is a core module of the Hibernate framework that enables simple entity auditing and change tracking using annotations and simple configuration steps.

Hibernate Envers is a core module of Hibernate.

Envers provides simple entity auditing and change tracking by using Java annotations to influence what it to be tracked by the change management listeners. The module allows you to save historical changes (CRUD operations) made on your persistent entities in audit specific tables that are created by Envers automatically.

Official site:
http://www.hibernate.org/orm/envers

To take advantage of Hibernate Envers, you first need to add the dependency. You simply need to configure the dependency as follows:

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-envers</artifactId>
  <version>5.2.8.Final</version>
</dependency>

It's important to remember that the version of Envers you should use must match the same version of Hibernate that your application is using.

A Simple Example

@Entity
@Audited
public class Person {
  @Id
  private Integer id;
  private String name;
  private Date dateOfBirth;
  // getter/setters
}

Guides And Tutorials:

883 questions
12
votes
4 answers

Audit table using "Envers" in Spring Hibernate java project

We need to audit the existing table using envers. we don't have hibernate.xml instead of we are using application-context.xml. And we are creating schema through "liquibase-changeset", then how do I create through annotations like @Entity and…
SST
  • 2,054
  • 5
  • 35
  • 65
11
votes
5 answers

Get previous version of entity in Hibernate Envers

I have an entity loaded by Hibernate (via EntityManager): User u = em.load(User.class, id) This class is audited by Hibernate Envers. How can I load the previous version of a User entity?
razenha
  • 7,660
  • 6
  • 37
  • 53
11
votes
2 answers

All @Version fields in AUD table are null when used hibernate-envers, but in entity - table filled okey?

There is application spring+jpa+envers(hibernate) envers needs to save history of entities in special table. After I saved a few times my entity, I expected to see filled version field in USER table and filled version field in USER_AUT. But actual…
Roberto
  • 1,288
  • 5
  • 23
  • 47
11
votes
2 answers

Javers - What are advantages of using Javers instead of Envers?

I am developing a RESTful API using Spring Data REST. Now for auditing, Spring does have the option to auditing meta data like created_date and modified_date but they don't provide entity versioning. Currently there are two popular libraries for…
Charlie
  • 3,113
  • 3
  • 38
  • 60
11
votes
3 answers

How to retrieve Username from customRevisionEntity

We are using Hibernate-envers 3.6.3.Final and I am getting tables are generated properly with @Audited annotations. I am using CustomRevisionEntity to store the user information and CustomRevisionListenner is stored the user information as well. But…
SST
  • 2,054
  • 5
  • 35
  • 65
11
votes
1 answer

Spring Data Rest: Expose new endpoints for Repository that extends Revision Repository

I would like to expose new endpoints for my repository which also extends RevisionRepository. @RepositoryRestResource(collectionResourceRel = "persons", itemResourceRel = "person", path = "persons") public interface PersonRepository extends…
Chad
  • 2,041
  • 6
  • 25
  • 39
10
votes
3 answers

How to find all revisions for an entity using spring data envers?

I am using spring-data-envers in my spring boot application. I can successfully log the audits on my entities. Now, I need to show audited data to the user in UI. Like there will be search form where user can select duration and entity for which he…
ajm
  • 12,863
  • 58
  • 163
  • 234
10
votes
1 answer

Hibernate join table with other audit table

I have an audit table with revisioning and I want to create another table with one-to-many relation with the audit table revision. The audit revision will pointing to the new table data. How can I do that?
Jordan Borisov
  • 1,603
  • 6
  • 34
  • 69
10
votes
4 answers

How to delete entries from my audit table?

I am currently working with Hibernate Envers. How to delete entries in the audit table related to the entity I want to delete? My entity has no relation with other entities. I figured out that I have to do that in onPostDelete method of my custom…
Laurent T
  • 1,070
  • 4
  • 13
  • 25
10
votes
3 answers

Hibernate Envers - REVINFO table doesn't exist

I'm using Hibernate 4.3.6, and I tried making use of the Envers functionality by adding the @Audited annotation to one of my @Entity classes. (The envers jar - hibernate-envers-4.3.6.Final.jar - is on my CLASSPATH.) When I run my code, which works…
rweiser
  • 319
  • 1
  • 3
  • 13
10
votes
3 answers

Adding Envers to an existing database

I have a Hibernate-based app in production, with a large database. I need to add auditing to two entities (two tables) in this application, and I've decided to go with Envers. For every INSERT, UPDATE or DELETE, Envers adds a new record to the…
Daniel Serodio
  • 4,229
  • 5
  • 37
  • 33
10
votes
5 answers

Conditional Envers Auditing

I have a requirement where I want to audit records only on change of Status field. I've followed documentation chapter tutorial "15.8. Conditional auditing". Step 1: Turn off automatic Envers event listeners registration. I have following:
Shirish Bathe
  • 627
  • 9
  • 22
10
votes
4 answers

Listing latest revision of each entity with envers

I am trying to retrieve the latest revision of all entities, that have not been deleted. Doing this in SQL is very simple with an subselect: select * from article_aud aud1 where rev in (select max(rev) from article_aud aud2 where aud1.id =…
powerMicha
  • 2,753
  • 1
  • 24
  • 31
9
votes
2 answers

REVINFO table is missing the sequence "revinfo_seq"

I am migrating to SpringBoot 3.0.1 and updated "hibernate-envers" version to "6.1.6.Final". My DB is PostgreSQL 13.6. Hibernate is configured to create the DB schema: spring.jpa.hibernate.ddl-auto:create After starting the application I get the…
vfluegel
  • 93
  • 4
9
votes
1 answer

Audit ManyToMany Relationships using Hibernate Envers

I'm using Hibernate Envers in order to audit my entities. But I have a problem. I want to audit an Entity that have a ManyToMany relationship. I found that exists an @AuditJoinTable but I don't have idea how it works. Can someone giveme an example?
jgarciad
  • 335
  • 2
  • 10
1
2
3
58 59