2 Replies Latest reply on May 11, 2006 1:07 PM by Henrique Sousa

    EntityListener repeatedly called due to ClassDefNotFoundErro

    Henrique Sousa Newbie

      Hi guys,

      I am trying to attach an audit listener to my EJB 3.0 entities. All my entities already have a listener to set all string properties to upper case (which works fine). My audit listener does not modify any properties from the audited entity, just reads them and also read the current value of that entity.

      When reading values, the audit process calls a method from another session bean which executes a named query. When that named query runs, the @PreUpdate method of the audit listener is called again for the same entity as the first time (not the one involved in the executed query). That becomes an infinite loop until a StackOverflowError is thrown.

      Is there any way to avoid this? Here is the recurrent part of the thread stack trace:

      javax.ejb.EJBTransactionRolledbackException: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
       ...
       at $Proxy148.registrarAtualizacao(Unknown Source)
       at com.diaup.worldnet.dominio.LogListener.antesDeSalvar(LogListener.java:44)
       at sun.reflect.GeneratedMethodAccessor102.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.hibernate.ejb.event.ListenerCallback.invoke(ListenerCallback.java:30)
       at org.hibernate.ejb.event.EntityCallbackHandler.callback(EntityCallbackHandler.java:75)
       at org.hibernate.ejb.event.EntityCallbackHandler.preUpdate(EntityCallbackHandler.java:60)
       at org.hibernate.ejb.event.EJB3FlushEntityEventListener.invokeInterceptor(EJB3FlushEntityEventListener.java:40)
       at org.hibernate.event.def.DefaultFlushEntityEventListener.handleInterception(DefaultFlushEntityEventListener.java:301)
       at org.hibernate.event.def.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:241)
       at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:121)
       at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
       at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
       at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
       at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:957)
       at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1102)
       at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
       at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:756)
       at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:63)
       at com.diaup.worldnet.negocio.admin.UsuarioServiceBean.findByLogin(UsuarioServiceBean.java:128)
       at sun.reflect.GeneratedMethodAccessor101.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:109)
       at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:196)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:54)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:225)
       at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:55)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102)
       at $Proxy119.findByLogin(Unknown Source)
       at com.diaup.worldnet.negocio.log.RegistraLogServiceBean.usuarioAutenticado(RegistraLogServiceBean.java:113)
       at com.diaup.worldnet.negocio.log.RegistraLogServiceBean.novoRegistro(RegistraLogServiceBean.java:106)
       at com.diaup.worldnet.negocio.log.RegistraLogServiceBean.registrarAtualizacao(RegistraLogServiceBean.java:82)
       at sun.reflect.GeneratedMethodAccessor103.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:109)
       at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:196)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:54)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:181)
       at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:79)
       at $Proxy148.registrarAtualizacao(Unknown Source)
       at com.diaup.worldnet.dominio.LogListener.antesDeSalvar(LogListener.java:44)
      


        • 1. Re: EntityListener repeatedly called
          Henrique Sousa Newbie

          I forgot to mention that one of the "caused by" traces is a ClassDefNotFoundError for org.hibernate.action.EntityUpdateAction, but I checked that class and it does exist in the shared library hibernate3.jar. I'm using JBoss 4.0.4 CR2

          • 2. Re: EntityListener repeatedly called
            Henrique Sousa Newbie

            I have solved the problem by introducing a static ThreadLocal variable to check if the listener is executing when it is called the second time. If it is, it just returns and causes no further listener calls.

            Now I face a second problem: the entity that I get from storage has a many-to-many association, and a many-to-one association wich has a many-to-many association on its own turn. It happens that hibernate just pops SQL commands that deletes these two many-to-many associations (which has some catastrophic consequences). I think I'm going to get a JIRA report on this.