3 Replies Latest reply on Apr 21, 2010 1:08 PM by zander35

    RevisionListener not being called

      Hello,

       

      I'm trying to follow the example in the documentation Chapter 4 about logging data for revisions. I'm using Hibernate 3.5.1 through Spring 2.5.4 with Oracle 10g and Tomcat  6.

       

      Like the example in the documentation, I just need to record the user in addition to the default revision fields. I'm assuming that if I don't specify another table name it will continue to use the REVINFO table and that I need to add a column to REVINFO for the new field, but I haven't got that far. So far I added what I believe is the correct entity and listener below, but nothing happens. On save or update no break points ever get hit in my listener. Is there anything else I need to do to plug in this listener in to Spring?

       

      Any help is MUCH appreciated!!

       

      Here's my code:

       

      public class RevisionListener implements org.hibernate.envers.RevisionListener
      {
          @Override
          public void newRevision(Object defaultEntity)
          {
                       MyRevisionEntity revisionEntity = (MyRevisionEntity) defaultEntity;

       

                       revisionEntity.setLastUpdateUser("testUser");
          }

      }

       


      @Entity
      @RevisionEntity(RevisionListener.class)
      public class MyRevisionEntity extends DefaultRevisionEntity
      {
          private static final long serialVersionUID = 1L;
         
          private String lastUpdateUser;
         
          public String getLastUpdateUser()
          {
              return lastUpdateUser;
          }
          public void setLastUpdateUser(String lastUpdateUser)
          {
              this.lastUpdateUser = lastUpdateUser;
          }
      }

        • 1. Re: RevisionListener not being called
          hernanbolido

          Hi Alex!

           

          Did you added the envers events in your configuration?

           

          Regards. Hernán.

          1 of 1 people found this helpful
          • 2. Re: RevisionListener not being called

            Thanks for the response. I do have the listeners that I originally needed to setup envers with, but I didn't add anything specific to the revisionListener. Are you saying that I need to add that as well? Do you know what the entry key for that would be in my xml file?

             

            Attached is what my hibernate properties look like as setup through a spring application context xml. I pulled out all the lines for my hbm.xml files to make it more legible.

             

            Thanks

             

            Alex

            • 3. Re: RevisionListener not being called

              I figured out my problem. I did not realize that I needed to add a new mapping file (hbm.xml) for the new RevisionEntity which I created. Once I added the new hbm.xml for my revision entity (with the new column I added to the REVINFO table for the user), envers picked it up on startup.

               

              Thanks

               

              Alex