2
I need to keep a log of all transactions of an entity with Hibernate Envers. I set persistence.xml as below:
<!-- Configurações do Envers -->
<property name="hibernate.ejb.event.post-insert" value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.post-update" value="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.post-delete" value="org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.pre-collection-update" value="org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.pre-collection-remove" value="org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.post-collection-recreate" value="org.hibernate.envers.event.AuditEventListener" />
I created an Author class as below:
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import org.hibernate.envers.Audited;
@Entity
@Audited
public class Autor {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String nome;
@OneToMany(mappedBy = "autor")
private List<Livro> livro;
public Autor() {
}
public Autor(String nome) {
this.nome = nome;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public List<Livro> getLivro() {
return livro;
}
public void setLivro(List<Livro> livro) {
this.livro = livro;
}
@Override
public String toString() {
return "Autor [id=" + id + ", nome=" + nome + ", livro=" + livro + "]";
}
}
Checking what happened in the Database after some insertions and changes in some records, I noticed that the modifications in the table are actually being audited, but I’m not finding a way to store the date and time of each of the modifications. Is there any annotation that can be placed in the class that records this information?