5 Replies Latest reply on Feb 12, 2013 5:16 AM by saikiran kulkarni

    envers property not found exception

    saikiran kulkarni Newbie

      Hi,

      I am working on envers...

      I am able persist the entities with audit deatils by default implementations..

      I want to add username to the revinfo so i extended defaultrevision class and i have written the revision listener ,,,

      when run test givivng "

       

       

       

      Caused by:

       

      org.hibernate.PropertyNotFoundException

      :

       

       

      field [modifiedEntityNames] not found on com.arisglobal.entities.CustomRevisionEntity..

       

      so plz help

       

      //package com.arisglobal.entities;
      //
      //
      //import javax.persistence.Entity;
      //
      //import org.hibernate.envers.DefaultRevisionEntity;
      //import org.hibernate.envers.RevisionEntity;
      //
      //
      //@Entity
      //@RevisionEntity //(ImplementedRevisionListener.class)
      //public class ExtendedRevisionEntity extends DefaultRevisionEntity {
      //
      //
      //
      //
      //
      //
      // private String userName;
      //
      //
      //
      // public String getUserName() {
      //  return userName;
      // }
      //
      // public void setUserName(String userName) {
      //  this.userName = userName;
      // }
      //
      //
      //
      //
      //
      //}


      package com.arisglobal.entities;

      import java.io.Serializable;
      import java.text.DateFormat;
      import java.util.Date;

      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import javax.persistence.Id;
      import javax.persistence.Table;
      import javax.persistence.Transient;

      import org.hibernate.envers.RevisionEntity;
      import org.hibernate.envers.RevisionNumber;
      import org.hibernate.envers.RevisionTimestamp;

      @Entity
      @Table(name="REVISIONS")
      @RevisionEntity(CustomRevisionListener.class)
      public class CustomRevisionEntity implements Serializable {
      private static final long serialVersionUID = -1255842407304508513L;

      @Column
      @Id
      @GeneratedValue
      @RevisionNumber
      private int id;


      @Column
      @RevisionTimestamp
      private long timestamp;

      @Column
      private String username;

      public int getId() {
          return id;
      }

      public void setId(int id) {
          this.id = id;
      }

      @Transient
      public Date getRevisionDate() {
          return new Date(timestamp);
      }

      public long getTimestamp() {
          return timestamp;
      }

      public void setTimestamp(long timestamp) {
          this.timestamp = timestamp;
      }

      public String getUsername() {
          return username;
      }

      public void setUsername(String username) {
          this.username = username;
      }

      public boolean equals(Object o) {
          if(this == o) return true;
          if(!(o instanceof CustomRevisionEntity)) return false;

          CustomRevisionEntity that = (CustomRevisionEntity) o;

          if(id != that.id) return false;
          if(timestamp != that.timestamp) return false;
          if(timestamp != that.timestamp) return false;
          if(username != that.username) return false;

          return true;
      }

      public int hashCode() {
          int result;
          result = id;
          result = 31 * result + (int) (timestamp ^ (timestamp >>> 32));
          return result;
      }

      public String toString() {
          return "DefaultRevisionEntity(user = " + username + "id = " + id + ", revisionDate = " + DateFormat.getDateTimeInstance().format(getRevisionDate()) + ")";
      }
      }

      package com.arisglobal.entities;
      //
      //import org.hibernate.envers.RevisionListener;
      //
      //public class ImplementedRevisionListener  implements RevisionListener{
      //
      // public void newRevision(Object revisionEntity) {
      //  // TODO Auto-generated method stub
      // 
      // 
      //  ExtendedRevisionEntity extendedRevisionEntity = (ExtendedRevisionEntity) revisionEntity;
      // 
      //  extendedRevisionEntity.setUserName("saikiran");
      // 
      // 
      //
      // }
      //
      //}



      import org.hibernate.envers.RevisionListener;

      public class CustomRevisionListener implements RevisionListener {

      public void newRevision(Object revisionEntity) {
          CustomRevisionEntity revision = (CustomRevisionEntity) revisionEntity;
          revision.setUsername("username"); //for testing
      }

      }

        • 1. Re: envers property not found exception
          Rafael Neves Newbie

          what's version of you hibernate envers and hibernate core?

          in version 1.X of envers, is necessary add properties in  persistence.xml

           

                                       <property name="hibernate.ejb.event.post-insert" value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener" />

                                        <property name="hibernate.ejb.event.post-update" value="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener" />

                                        <property name="hibernate.ejb.event.post-delete" value="org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener" />

                                        <property name="hibernate.ejb.event.pre-collection-update" value="org.hibernate.envers.event.AuditEventListener" />

                                        <property name="hibernate.ejb.event.pre-collection-remove" value="org.hibernate.envers.event.AuditEventListener" />

                                        <property name="hibernate.ejb.event.post-collection-recreate" value="org.hibernate.envers.event.AuditEventListener" />

          • 2. Re: envers property not found exception
            saikiran kulkarni Newbie

            using following dependencies

            <dependency>

                                          <groupId>org.hibernate</groupId>

                                          <artifactId>hibernate-entitymanager</artifactId>

                                          <version>4.1.4.Final</version>

                                </dependency>

             

             

                                <dependency>

                                          <groupId>org.hibernate</groupId>

                                          <artifactId>hibernate-envers</artifactId>

                                          <version>4.1.7.Final</version>

                                </dependency>

             

            when I add properties in persistence.xml getting following exception

            javax.persistence.PersistenceException: [PersistenceUnit: envers] Unable to build EntityManagerFactory

                      at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)

                      at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)

                      at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)

                      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)

                      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)

                      at com.arisglobal.util.EntityManagerUtil.getEntityManager(EntityManagerUtil.java:17)

                      at com.arisglobal.dao.EmployeeDAO.createEmployee(EmployeeDAO.java:23)

                      at com.arisglobal.service.EmployeeServiceImpl.createEmployee(EmployeeServiceImpl.java:16)

                      at com.arisglobal.test.EmployeeServiceTest.testCreateEmployee(EmployeeServiceTest.java:27)

                      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

                      at java.lang.reflect.Method.invoke(Unknown Source)

                      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)

                      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

                      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)

                      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)

                      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)

                      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)

                      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)

                      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)

                      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)

                      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)

                      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)

                      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)

                      at org.junit.runners.ParentRunner.run(ParentRunner.java:300)

                      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

                      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

                      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

                      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

                      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

                      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

            Caused by: org.hibernate.HibernateException: Could not instantiate requested listener [org.hibernate.envers.event.AuditEventListener]

                      at org.hibernate.ejb.event.JpaIntegrator.instantiate(JpaIntegrator.java:260)

                      at org.hibernate.ejb.event.JpaIntegrator.integrate(JpaIntegrator.java:137)

                      at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:301)

                      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750)

                      at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)

                      at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)

                      ... 31 more

            Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [org.hibernate.envers.event.AuditEventListener]

                      at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:141)

                      at org.hibernate.ejb.event.JpaIntegrator.instantiate(JpaIntegrator.java:257)

                      ... 36 more

            Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.envers.event.AuditEventListener

                      at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$1.findClass(ClassLoaderServiceImpl.java:99)

                      at java.lang.ClassLoader.loadClass(Unknown Source)

                      at java.lang.ClassLoader.loadClass(Unknown Source)

                      at java.lang.Class.forName0(Native Method)

                      at java.lang.Class.forName(Unknown Source)

                      at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:138)

                      ... 37 more

            • 3. Re: envers property not found exception
              Rafael Neves Newbie

              remove the properties in you persistence.xml

              <property name="hibernate.ejb.event.post-insert" value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener" /> and others.

               

              in envers 4.X this properties not is used.

              • 4. Re: envers property not found exception
                saikiran kulkarni Newbie

                then, whta is the solution for my above problem...

                I wanted to add user details in revinfo table ...send me any tutorial..

                Thanks

                • 5. Re: envers property not found exception
                  saikiran kulkarni Newbie

                  extend custom class by customtrackingrevisionentity instead of customrevision entity