2 Replies Latest reply on Jan 24, 2008 9:24 AM by lpmon

    Injected EntityManager in SLSB after an exception

    lpmon Novice

      Environment: JBoss AS 4.0.5, Hibernate 3.2.5, Hibernate EM 3.3.1

      I am using CMP. I have an injected entitymanager (em) in an SLSB I use to persist new rows into the DB.

      After an exception is thrown (in this case a dup key) - subsequent calls to the SLSB method that does the persist seems to be using the same em that was rendered unusable by the exception.

      I say "unusable" because per Hibernate documentation an em must be closed after an exception. BUT: I am using CMP with @PersistenceContext for injection so the container should handle that. Right? I would think the container would inject a new em for the next call to the SLSB method???? Is there something I must do to force the new em to be injected?

      On the first insert with a dup key I get an EntityExistsException (this is expected). But, on the next call to the SLSB I get the stack trace below which to me indicates the SLSB still has the old em and is trying to use it:

      2008-01-23 10:51:15,009 ERROR [STDERR] | javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: EntityManager must be access within a transaction
      2008-01-23 10:51:15,009 ERROR [STDERR] javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: EntityManager must be access within a transaction
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:93)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:102)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:211)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:79)
      2008-01-23 10:51:15,009 ERROR [STDERR] at $Proxy148.saveEvent(Unknown Source)
      2008-01-23 10:51:15,009 ERROR [STDERR] at com.shockwatch.swevents.SWEvent.process(SWEvent.java:358)
      2008-01-23 10:51:15,009 ERROR [STDERR] at com.shockwatch.bufs.EventBuf.processEvents(EventBuf.java:503)
      2008-01-23 10:51:15,009 ERROR [STDERR] at com.shockwatch.bufs.EventBuf.process(EventBuf.java:485)
      2008-01-23 10:51:15,009 ERROR [STDERR] at com.shockwatch.server.RFMsg.rcvUnitData(RFMsg.java:939)
      2008-01-23 10:51:15,009 ERROR [STDERR] at com.shockwatch.server.RFMsg.RcvSendData(RFMsg.java:685)
      2008-01-23 10:51:15,009 ERROR [STDERR] at com.shockwatch.server.RFMsg.ProcessInbound(RFMsg.java:393)
      2008-01-23 10:51:15,009 ERROR [STDERR] at com.shockwatch.server.RFPakIn.ProcessMessages(RFPakIn.java:160)
      2008-01-23 10:51:15,009 ERROR [STDERR] at com.shockwatch.server.RFPakIn.process(RFPakIn.java:61)
      2008-01-23 10:51:15,009 ERROR [STDERR] at com.shockwatch.dbfacade.SWUnit.run(SWUnit.java:297)
      2008-01-23 10:51:15,009 ERROR [STDERR] at com.shockwatch.ejb3.session.PacketProcessorBean.processPacket(PacketProcessorBean.java:38)
      2008-01-23 10:51:15,009 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2008-01-23 10:51:15,009 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      2008-01-23 10:51:15,009 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      2008-01-23 10:51:15,009 ERROR [STDERR] at java.lang.reflect.Method.invoke(Unknown Source)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:37)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:98)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:53)
      2008-01-23 10:51:15,009 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor223.invoke(Unknown Source)
      2008-01-23 10:51:15,009 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      2008-01-23 10:51:15,009 ERROR [STDERR] at java.lang.reflect.Method.invoke(Unknown Source)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:46)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
      2008-01-23 10:51:15,009 ERROR [STDERR] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
      2008-01-23 10:51:15,040 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-01-23 10:51:15,040 ERROR [STDERR] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
      2008-01-23 10:51:15,040 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-01-23 10:51:15,040 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
      2008-01-23 10:51:15,040 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-01-23 10:51:15,040 ERROR [STDERR] at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
      2008-01-23 10:51:15,040 ERROR [STDERR] at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:102)
      2008-01-23 10:51:15,040 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-01-23 10:51:15,040 ERROR [STDERR] at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
      2008-01-23 10:51:15,040 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-01-23 10:51:15,040 ERROR [STDERR] at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
      2008-01-23 10:51:15,040 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-01-23 10:51:15,040 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:211)
      2008-01-23 10:51:15,040 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:79)
      2008-01-23 10:51:15,040 ERROR [STDERR] at $Proxy145.processPacket(Unknown Source)
      2008-01-23 10:51:15,040 ERROR [STDERR] at com.shockwatch.server.PakInRunner.run(PakInRunner.java:31)
      2008-01-23 10:51:15,040 ERROR [STDERR] at com.shockwatch.util.ThreadPool$PooledThread.run(ThreadPool.java:55)
      2008-01-23 10:51:15,056 ERROR [STDERR] Caused by: javax.persistence.TransactionRequiredException: EntityManager must be access within a transaction
      2008-01-23 10:51:15,056 ERROR [STDERR] at org.jboss.ejb3.entity.ManagedEntityManagerFactory.verifyInTx(ManagedEntityManagerFactory.java:150)
      2008-01-23 10:51:15,056 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntityManager.persist(TransactionScopedEntityManager.java:174)