Auditing, History of database modifications with Hibernate — Envers Solution !
Envers is one of the Hibernate’s project sponsored by Redhat. Works with Hibernate and Hibernate Entity Manager.

Aims to enable easy auditing of persistent classes. For each audited entity you must annotate your persistent clases with @Audited, a table will be created, which will hold the history of changes made to the entity.

The idea is very similar to CVS or Subersion. Each transaction with updates, deletes or inserts made in the database with hibernate generate a new revision number. One transaction is one revision.

Envers provide a simple way to retrive your data of a revision using: revision number, date, queries with min and max function between others.

You can use Envers wherever Hibernate works: standalone, inside JBoss AS, with JBoss Seam or Spring.

It’s very easy …

@Entity

@Audited

public class Usuario {

public enum Rol{

EMPRESA, ADMINISTRADOR,MESA_ENTRADA;

}

private Long id;

private String usuario;

private String contrasenia;

private Rol rol;

@Id

@GeneratedValue

public Long getId() {

return id;

}

public void setId(Long id) {

this.id = id;

}
['Blog Moove-It']
['Hibernate', 'Envers', 'Auditing', 'Java Ee', 'Java']