4 Replies Latest reply on Jan 18, 2013 3:02 PM by Rafael Neves

    Create my Custom RevisionListener for persist user and others data on REVINFO table.

    Rafael Neves Newbie

      hi, guys.

       

      I'm try create my custom RevisionListener following this documentation: http://docs.jboss.org/hibernate/core/4.1/devguide/en-US/html/ch15.html#envers-revisionlog

      but, my custom class don't work.

      what's necessary for that my RevisionListener working in my project?

      I'm using Envers <version>4.1.0.Final</version>

      is necessary configuration on .properties file?

       

       

      my class:

       

       

      1. @Entity 
      2. @Table(name="REVINFO"
      3. @RevisionEntity(MyRevisionListener.class
      4. public class MyRevisionEntity extends DefaultRevisionEntity { 
      5.     /**
      6.      *
      7.      */ 
      8.     private static final long serialVersionUID = 1L; 
      9.     private String username; 
      10.  
      11.     public String getUsername() { 
      12.         return username; 
      13.     } 
      14.  
      15.     public void setUsername(String username) { 
      16.         this.username = username; 
      17.     } 



       

       

       

       

      1. public class MyRevisionListener implements RevisionListener { 
      2.  
      3.     @Override 
      4.     public void newRevision(Object revisionEntity) { 
      5.         MyRevisionEntity revision = (MyRevisionEntity) revisionEntity; 
      6.         Set<PrincipalAxx> principalSet = SecurityContextAssociation.getSubject().getPrincipals(PrincipalAxx.class); 
      7.         PrincipalAxx user = principalSet.iterator().next(); 
      8.         revision.setUsername(user.getFullName()); 
      9.     } 
      10.