Auditing With Envers

Auditing With Envers

You can audit any changes to any entity using envers.

Dependency and configuration found at: https://hibernate.org/orm/envers/

Then annnotate entities to audit:

@Entity
@Audited
public class Employee { ... }

Now when you make changes to an entity an audit entry will be created automatically.

Employee emp = employeeRepo.findById(1L);
emp.setSalary(75000);
employeeRepo.save(emp); // audit table will be updated here automatically to an audit table

Audit tables can be created automatically by Spring/Hibernate with hibernate.hbm2ddl.auto=update

Envers is a useful library for building in auditing into your existing Hibernate application.