2 Replies Latest reply on Sep 2, 2011 6:58 AM by eduterio1

    Hibernate Envers: Class Loading issue.

    eduterio1

      Hello,

       

      I am trying to integrate Hibernate Envers in an already developed application, and I am finding a problem when Envers tries to persist audited Data.

      I ship the Hibernate Envers JAR inside an EAR package, and it throws an ugly exception regarding to class loader and some kind of conflict. The exception is shown below.

      If I avoid shipping the Envers JAR inside the EAR and I place it in the "lib" directory of JBoss, then everything works fine, but i need to ship the library along with the application, since I have no access to this global "lib" directory.

       

      I am deploying on JBoss 5.1.0.GA, using Hibernate 3.3.GA and Envers 1.2.2.GA.

      Any clue?

       

      Thank you very much!

       

      The exception is this one:

       

      15:31:21,621 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_2] TwoPhaseCoordinator.beforeC

      ompletion - failed for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@84697f

      java.lang.LinkageError: loader constraint violation: when resolving interface method "org.hibernate.Transaction.register

      Synchronization(Ljavax/transaction/Synchronization;)V" the class loader (instance of org/jboss/classloader/spi/base/Base

      ClassLoader) of the current class, org/hibernate/envers/synchronization/AuditSyncManager, and the class loader (instance

      of org/jboss/classloader/spi/base/BaseClassLoader) for resolved class, org/hibernate/Transaction, have different Class

      objects for the type javax/transaction/Synchronization used in the signature

              at org.hibernate.envers.synchronization.AuditSyncManager.get(AuditSyncManager.java:56)

              at org.hibernate.envers.event.AuditEventListener.onPostUpdate(AuditEventListener.java:163)

              at org.hibernate.action.EntityUpdateAction.postUpdate(EntityUpdateAction.java:200)

              at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:179)

              at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)

              at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)

              at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)

              at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:32

      1)

              at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)

              at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)

              at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)

              at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:504)

              at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.j

      ava:101)

              at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:269)

              at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:89)

              at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)

              at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.ja

      va:1423)

              at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:137)

              at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75)

              at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:170)

              at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)

              at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:190)

              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

              at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)

              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

              at org.jboss.ejb3.security.RunAsSecurityInterceptorv2.invoke(RunAsSecurityInterceptorv2.java:94)

              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

              at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:2

      01)

              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

              at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:186)

              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

              at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)

              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

              at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)

              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

              at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)

       

              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

              at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:421)

              at org.jboss.ejb3.remoting.IsLocalInterceptor.invokeLocal(IsLocalInterceptor.java:85)

              at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:72)

              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

              at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)

              at $Proxy1342.invoke(Unknown Source)

              at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHand

      lerBase.java:207)

              at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHand

      lerBase.java:164)

        • 1. Re: Hibernate Envers: Class Loading issue.
          adamw

          If you bundle Envers with the applicaiton, make sure that the Hibernate jars don't get bundled as well. If you use Maven, you may need to add som excludes.

           

          Adam

          • 2. Re: Hibernate Envers: Class Loading issue.
            eduterio1

            Thanks for your answer Adam. I solved it and the problem had nothing to do with hibernate or envers, the problem was that I was shipping my own version of JTA in the EAR and it failed to cast a JBoss JTA class to the embedded JTA class (loaded by another classloader).

             

            Thanks for your support and great job!