Hello all,
I discovered Hibernate Envers yesterday. It's an amazing tool. I use it to historize my entities.
I have transients properties in my audited entities. I would like too add them in my custom revision entity.
So I need to retreive the audited entity in my custom revision listener, but I don't know how :(
Could you help me please ?
Following, my custom revision entity and my custom revision listener (the classes and properties names are in french... ;) :
Code:
@Entity
@RevisionEntity(HistorisationListener.class)
public class Historisation extends DefaultRevisionEntity {
private static final long serialVersionUID = -5087706580347772924L;
private String loginUtilisateur = "";
private String origineHistorique = "";
public String getLoginUtilisateur() {
return loginUtilisateur;
}
public void setLoginUtilisateur(String loginUtilisateur) {
this.loginUtilisateur = loginUtilisateur;
}
public String getOrigineHistorique() {
return origineHistorique;
}
public void setOrigineHistorique(String origine) {
this.origineHistorique = origine;
}
}
Code:
public class HistorisationListener implements RevisionListener {
@Override
public void newRevision(Object historisationEntity) {
SimpleDAO dao = null;
SessionContext sessionContext = null;
dao = JNDILocator.lookupBean(SimpleDAO.class);
if(null != dao){
sessionContext = dao.getSessionContext();
}
if(null != sessionContext){
String loginUtilisateur = sessionContext.getCallerPrincipal().getName();
String origine = "";
Historisation historisation = (Historisation) historisationEntity;
historisation.setLoginUtilisateur(loginUtilisateur);
historisation.setOrigineHistorique(origine);
}
}
}