1 Reply Latest reply on Feb 27, 2012 7:47 AM by ashmcconnell

    Confusion on how to add extra revision info

    ashmcconnell

      Hi Folks,

       

      I'm having a little trouble adding username data to revisions using Envers.

       

      I have managed to get envers to write revision information for one of my entities (to a _AUD table).  I would also like to associate a username with each revision, so we can track who made a particular change.

       

      I added a Revision Entity like this: -

       

      {code}

      @RevisionEntity(MyRevisionListener.class)

      public class MyRevisionEntity extends DefaultRevisionEntity {

       

        private String username;

       

        public String getUsername() {

          return username;

        }

       

        public void setUsername(String username) {

          this.username = username;

        }

       

      }

      {code}

       

       

      and a Revision Listener: -

       

       

      {code}

      public class MyRevisionListener implements RevisionListener {

       

        @Override

        public void newRevision(Object revisionEntity) {

          MyRevisionEntity smpRE = (MyRevisionEntity) revisionEntity;

       

          Object princ = SecurityContextHolder.getContext().getAuthentication().getPrincipal();

       

          if (princ == null) {

            smpRE.setUsername("USER_NOT_FOUND");

          }

          else {

            SecureMember sm = (SecureMember) princ;

            smpRE.setUsername(sm.getUsername());

          }

        }

       

      }

      {code}

       

       

      I expected a record to be created in the MyRevisionEntity table each time a new revision was created.  It seems to just have a single entry.  Have I misunderstood the purpose of the RevisionEntity/Listener or made a mistake in configuration?  The _AUD tables seem to be working as expected by the way.

       

      Thanks for your help

      All the best,

      Ash

        • 1. Re: Confusion on how to add extra revision info
          ashmcconnell

          Hi Folks,

           

          Ah, I found that my data had somehow become inconsistent.  When I was starting tomcat it was complaining about foreign key violations.  I removed all _AUD tables, MyRevisionEntity and REVINFO tables.  Now it works as I had thought.  I think perhaps it's because I didn't have the MyRevisionEntity revision entity at the start.

           

          All the best,

          Ash