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
6
votes
2 answers

NHibernate Envers: Cannot insert duplicate key in object

I'm using Envers to audit tables, but it's creating some audit tables for unknown/absent tables. It's looks like a Many To Many relation audit table for Many To One relations. Is this right? If it's, Why? dbo.HorarioFixo -…
user1938667
6
votes
1 answer

Getting modified properties by revision

I am using Hibernate Envers to audit my entities and properties (org.hibernate.envers.global_with_modified_flag=true). This seems to work, but now I'd like to get all properties of a specific entity which changed at a given revision, compared to the…
Dominik Sandjaja
  • 6,326
  • 6
  • 52
  • 77
6
votes
3 answers

Hibernate Envers - Doesn't write audit records for createQuery(...).executeUpdate(), only .persist() and .merge()

I have 3 ways things get written to the DB public void create(T object) { entityManager.persist(object); } public void update(T object) { object = entityManager.merge(object); } public int updateStatus(String id, String status) { …
babb
  • 423
  • 2
  • 15
  • 38
6
votes
1 answer

Can Envers use a different database?

Is possible for Hibernate Envers to use another database for audit tables?
romifz
  • 135
  • 10
5
votes
2 answers

Envers, PostgreSQL and TINYINT

We are using Envers with both Oracle and MySQL without any problem. We are now trying PostgreSQL but we have the problem that the audit tables are created with a column REVTYPE of type TINYINT. TINYINT is not supported by PostgreSQL. Is there a way…
Matteo
  • 14,696
  • 9
  • 68
  • 106
5
votes
2 answers

Envers custom revision listener

I am using Hibernate Envers in a Tomcat environment. It works fine. I do however need to be able to add the username of the user that changed the data that is to be audited. This can be done by implementing your own version of RevisionEntity. Then…
Brumlebass
  • 51
  • 1
  • 2
5
votes
1 answer

jboss 7 (envers 4) Unable to load class org.hibernate.envers.event.AuditEventListener

I port from hibernate Envers 3.6 to Envers 4.0. This new version doesn't have AuditEventListener. Old version requires: listeners I can't find how to configure the new version.
Vlada
  • 559
  • 2
  • 11
  • 27
5
votes
0 answers

Envers configuration with hibernate.cfg.xml

I am trying to use Envers to audit the updates/inserts into my tables. I have created audit tables with extension _AUDIT in the DB. But when I actually run the application, I dont see any entries in the audit tables. I even have no errors or…
5
votes
0 answers

Hibernate Envers ManyToMany change detection

I have entities with unidirectional ManyToMany relations. A document can be associated to multiple facilities and multiple floors. If a document is updated, the facilities and floors associated with the document should create a new revision in…
SimonH
  • 140
  • 2
  • 17
5
votes
1 answer

How to resolve deadlock in MySQL due to hibernate envers auditing?

While running few transactions in parallel, most of the time I get deadlock as : ------------------------ LATEST DETECTED DEADLOCK ------------------------ 2019-09-04 06:19:12 0x2b01917c7700 *** (1) TRANSACTION: TRANSACTION 14470484, ACTIVE 0 sec…
Rajat Goel
  • 2,207
  • 17
  • 35
5
votes
0 answers

How to implement @Auditable with dropwizard

I want to implement @Auditable with Dropwizard. Which will create the *_audit table and also store the details with Revinfo table? I am using Dropwizard with Liquibase. I have added @Auditable on Entity @Entity @Table(name =…
Sandesh Dumbre
  • 226
  • 2
  • 9
5
votes
1 answer

Hibernate envers 5.2.14 creates hibernate_sequence table even when not necessary

I switched my Spring application from Spring Boot 1.5.x to Spring Boot 2.0. I'm using Hibernate Envers and before the switching I had RevInfo table to store information about the revision. The id was an autoincrement. After the migration, Hibernate…
drenda
  • 5,846
  • 11
  • 68
  • 141
5
votes
1 answer

How to audit just part of superclass in hibernate?

I want to ask how to audit just a part of a superclass of entity, using hibernate annotations such as @AuditOverride, @Audited or else. Right now, I am using hibernate 5.2.12 version. The annotations I can use only in a sublcass, because the…
Dumbo
  • 1,630
  • 18
  • 33
5
votes
0 answers

Hibernate Envers load lazy entities for a revision

I'm using Spring Boot, Spring Data REST, Spring HATEOAS, Hibernate, Spring Data Envers. I'm auditing my entities in order to tracking all changes. I am consuming REST service from an Angular 4 application. My goal is display a lix of boxes for each…
drenda
  • 5,846
  • 11
  • 68
  • 141
5
votes
1 answer

Hibernate - Envers -> auditing / versioning of an attribute, but only if the value changed

I have a problem with Hibernate - Envers. I have a domain object with only one audited attribute status which can be one of the numbers 0,1,2,3,4,5. @Entity public class Item { ... @Audited private int status; ... other variables,…
Tim
  • 13,228
  • 36
  • 108
  • 159