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
7
votes
1 answer

Can I create Hibernate Envers specific tables using Liquibase

Our Java app is Spring based and we have domain classes and the corresponding schema generated via Liquibase. We are planning to add support for a single domain to be audited. a. We don't have hibernate.xml and hibernate.cfg.xml instead we are using…
SST
  • 2,054
  • 5
  • 35
  • 65
7
votes
1 answer

hibernate envers does not get triggered for jpa queries

I am using hibernate envers to audit events and it works fine along with Spring Data JPA Repository when i invoke repositoy.delete() or repository.save() But If I write a jpa query and delete the entity using a query , then it hibernate envers…
lives
  • 1,243
  • 5
  • 25
  • 61
7
votes
1 answer

How to force Hibernate Envers to commit a revision within a Spring @Transactional method

I'm using Hibernate Envers to persist object history. At certain points we want to capture a snapshot of the object graph state - and we can do this by knowing the corresponding Envers revision which we then store on an audit record. However we…
user598656
  • 442
  • 7
  • 10
7
votes
1 answer

Spring + Hibernate + Envers + multithreading - session is closed

We use Hibernate (with JPA) and Hibernate Envers to persist history of objects. The web application runs many threads, some of them are created by RMI method invocation from other applications, some of them are created by the application itself and…
Paweł Chorążyk
  • 3,584
  • 3
  • 27
  • 33
7
votes
2 answers

Hibernate envers, post-delete event throws constraint violation exception

Project uses Hibernate 3.5, Spring Webflow 2 and Hibernate Envers for auditing. Envers is configured in hibernate.cfg.xml. I have one-to-many relation mapping between entity 'ArticleGroup' and 'Article'. Table 'articles' has a foreign key…
Raistlin
  • 407
  • 1
  • 8
  • 19
6
votes
4 answers

How to generate Envers database schema with org.hibernate.tool.EnversSchemaGenerator?

I updated Hibernate to the 4.1.1.Final version. According to the documentation There are 2 ways to generate a database schema: Ant task org.hibernate.tool.ant.EnversHibernateToolTask. Run org.hibernate.tool.EnversSchemaGenerator from…
Viacheslav Dobromyslov
  • 3,168
  • 1
  • 33
  • 45
6
votes
1 answer

Hibernate Envers: How to capture who deleted an entity in audit table

I am using hibernate-envers with spring. Everything works just fine, except when I delete an entity, it does not change the values of updated_by and updated_date inside audit table, instead it saves an entity exactly as it was before (just copy)…
kzharas210
  • 440
  • 1
  • 5
  • 13
6
votes
1 answer

Hibernate Envers cannot delete entity

I really have a weird issue now. I just want to delete an entity. I am also using Hibernate envers for auditing. So now I want to delete this entity. Now I get following…
Flo19
  • 81
  • 1
  • 5
6
votes
2 answers

Hibernate audit log of fields' change

How can I log the changes of the entity into log files? Consider I have Person like this. import org.hibernate.envers.Audited; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.GeneratedValue; import…
mohsen Lzd
  • 313
  • 1
  • 4
  • 13
6
votes
1 answer

the hibernate-envers with liquibase

My question can be trival, but documentation for hibernate-envers say I need just 2 steps to make hibernate envers work: the hibernate-envers jar on the classpath, an @Audited annotation on the entity. First of all I added:
degath
  • 1,530
  • 4
  • 31
  • 60
6
votes
2 answers

Base model with @Audited

I use @Audited annotation for my base model. I extend that for all my entities. but it not work. Is there any method I can use that this is my base model @MappedSuperclass @Getter @Setter @Audited public abstract class BaseModelObject implements…
wthamira
  • 2,032
  • 2
  • 21
  • 40
6
votes
1 answer

Ways to pass additional data to Custom RevisionEntity in Hibernate Envers?

It's RESTful web app. I am using Hibernate Envers to store historical data. Along with revision number and timestamp, I also need to store other details (for example: IP address and authenticated user). Envers provides multiple ways to have a custom…
Anmol Gupta
  • 2,797
  • 9
  • 27
  • 43
6
votes
1 answer

Load ManyToOne Relation with Hibernate Envers - Eager/Lazy?

I use Hibernate Envers 4.3.10.Final. I have the following two JPA-classes: public class Factory { private int factoryID; .... } public class Trgs{ private int trgsID; @ManyToOne(fetch=FetchType.EAGER) …
java java
  • 405
  • 1
  • 11
  • 25
6
votes
3 answers

Hibernate Envers - include date of when change happened

We have just started using Hibernate Envers, and it works well for logging what changed, however, is there a way that it can also log when the change happened? So, can it add a datetime column to the audit table? According to the Envers…
Magick
  • 4,603
  • 22
  • 66
  • 103
6
votes
2 answers

Add additional column in audit table with hibernate envers

Is it possible to add additional column in audit table?? For example i have a table like this @Entity @Table(name="EmpEnverPrac") @Audited public class EmpEnverPractice { @Id @Column(name="ID") @GeneratedValue(strategy =…
rishi
  • 1,792
  • 5
  • 31
  • 63