-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Get the audited entity in Hibernate Envers
PostPosted: Thu Nov 22, 2012 11:57 am 
Newbie

Joined: Tue Jul 19, 2011 2:16 pm
Posts: 19
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);
      }
   }
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.