3 Replies Latest reply on Jan 11, 2012 9:33 AM by Adam Warski

    How register envers 4 listeners in persistence.xml ?

    Claudio Miranda Expert

      Hi, Looking into envers 4 documentation at [1] it doesn't says the listeners to configure.

      For envers 3.6. it says to register AuditEventListener which doesn't exist for envers 4.

      Looking into envers 4 javadoc, I suppose the listeners to register are displayed as below

       

       

      <property name="hibernate.ejb.event.post-insert"  value="org.hibernate.envers.event.EnversPostInsertEventListenerImpl"/>
      <property name="hibernate.ejb.event.post-update" value="org.hibernate.envers.event.EnversPostUpdateEventListenerImpl"/>
      <property name="hibernate.ejb.event.post-delete" value="org.hibernate.envers.event.EnversPostDeleteEventListenerImpl"/>

       

      However, running it throws errors

       

      Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.EnversPostUpdateEventListenerImpl]
          at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:141)
          at org.hibernate.ejb.event.JpaIntegrator.instantiate(JpaIntegrator.java:257)
          ... 35 more
      Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.EnversPostUpdateEventListenerImpl
      

       

      Looks like the comma is not recognized as an separator to multiple event listeners, if left only envers listeners, it throws.

       

       

      Caused by: org.hibernate.HibernateException: Could not instantiate requested listener [org.hibernate.envers.event.EnversPostUpdateEventListenerImpl]
          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:295)
          at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)
          at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:76)
          at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)
          ... 30 more
      Caused by: java.lang.InstantiationException: org.hibernate.envers.event.EnversPostUpdateEventListenerImpl
      

       

      So I ask, what is the correct configuration to register envers 4 in persistence.xml ?

       

      1. chap 15 http://docs.jboss.org/hibernate/core/4.0/devguide/en-US/html_single/#d0e4749