5 Replies Latest reply on Sep 3, 2009 12:21 PM by raffaele camanzo

    Batch procedure (with BTM) works only once per server restart.

    raffaele camanzo Newbie

      Hi all,


      I made a batch procedure to manipulate a large amount of data but I'm facing a strange behaviour.


      Environment:



      • AS: jBoss 4.2.3.GA




      • SEAM: latest (2.2.0.GA, also tried with 2.0.1, 2.1.2)




      • QUARTZ: latest (1.6.5 also tried with 1.6.1)




      • HIBERNATE: latest (3.3.2)



      The logic behind the procedure is quite simple: I have to execute a doSomething() operation on a huge amount of data, moreover doSomething() executes complex evaluations involving other data; CMT causes a transaction timeout exception then I decided to use BMT in order to split my batch over many transactions.


      Here's the scheduler method:


      @Asynchronous
      public QuartzTriggerHandle schedule(@Expiration Date when, @IntervalDuration Long interval) throws Exception {
      
           batchManager.doTheJob();
      
           return null;
      }
      




      The batchManager is the stateless bean I use to do the job:


      @Stateless
      @Name("batchManager")
      @TransactionManagement(TransactionManagementType.BEAN)
      @AutoCreate
      public class BatchManager implements BatchManagerInterface {
      
           private static final long serialVersionUID = 521276102521455864L;
      
           private static final int BATCH_SIZE = 100;
           
           @In
           private EntityManager entityManager;
           
           @Resource
           private UserTransaction userTransaction;
           
      ...
      
           public void doTheJob() throws Exception {
      
                userTransaction.begin();
                entityManager.joinTransaction();
      
                List<Debitore> debitori = new ArrayList<Debitore>();
                debitori.addAll(caricaDebitori(cliente));
                
                userTransaction.commit();
      
                int size = debitori.size();
                int index = 0;
                if(debitori.size() > 0) {
                    while((index < size)) {
                         try {
                             userTransaction.begin();
                             entityManager.joinTransaction();
                             
                                 int intsize = index + BATCH_SIZE > size ? size : index + BATCH_SIZE;
                                 for(; index < intsize; index++) {
                                      Debitore d = debitori.get(index);
                                      doAllTheStuff(d);
                                 }
      
                                 userTransaction.commit();
                         } catch(Exception e) {
                              e.printStackTrace();
                              userTransaction.rollback();
                         }
                    }
                }
           }
           
      }
      



      When I start the timer for the first time everything is ok, the Quartz scheduler starts the job and it completes successfully. After the IntervalDuration Quartz executes again the job but I get this exception:


      2009-09-02 16:39:50,081 DEBUG [it.finservice.odino.core.OLog] |WS-or-TIMER| [StatisticheOperativeManager.aggiornaDati] Stato della sessione. connesso: TRUE - aperto: TRUE - sp
      orco: FALSE
      2009-09-02 16:39:50,082 ERROR [STDERR] javax.persistence.PersistenceException: org.hibernate.SessionException: Session is closed!
      2009-09-02 16:39:50,083 ERROR [STDERR]  at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:76)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at it.finservice.odino.scheduler.statisticheOperative.bean.StatisticheOperativeManager.caricaClienti(StatisticheOperativeManager.java:1
      08)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at it.finservice.odino.scheduler.statisticheOperative.bean.StatisticheOperativeManager.aggiornaDati(StatisticheOperativeManager.java:82
      )
      2009-09-02 16:39:50,083 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at java.lang.reflect.Method.invoke(Method.java:585)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:30)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at sun.reflect.GeneratedMethodAccessor448.invoke(Unknown Source)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at java.lang.reflect.Method.invoke(Method.java:585)
      2009-09-02 16:39:50,083 ERROR [STDERR]  at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.ejb3.tx.BMTInterceptor.handleStateless(BMTInterceptor.java:71)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.ejb3.tx.BMTInterceptor.invoke(BMTInterceptor.java:131)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:214)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:184)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:81)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at $Proxy777.aggiornaDati(Unknown Source)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at java.lang.reflect.Method.invoke(Method.java:585)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.javassist.tmp.java.lang.Object_$$_javassist_seam_7.aggiornaDati(Object_$$_javassist_seam_7.java)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at it.finservice.odino.scheduler.statisticheOperative.StatisticheOperativeScheduler.schedule(StatisticheOperativeScheduler.java:74)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at java.lang.reflect.Method.invoke(Method.java:585)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      2009-09-02 16:39:50,084 ERROR [STDERR]  at org.jboss.seam.async.AsynchronousInterceptor.aroundInvoke(AsynchronousInterceptor.java:52)
      2009-09-02 16:39:50,085 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      2009-09-02 16:39:50,085 ERROR [STDERR]  at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
      2009-09-02 16:39:50,085 ERROR [STDERR]  at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
      2009-09-02 16:39:50,085 ERROR [STDERR]  at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
      2009-09-02 16:39:50,085 ERROR [STDERR]  at it.finservice.odino.scheduler.statisticheOperative.StatisticheOperativeScheduler_$$_javassist_seam_6.schedule(StatisticheOperativeSc
      heduler_$$_javassist_seam_6.java)
      2009-09-02 16:39:50,085 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2009-09-02 16:39:50,085 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      2009-09-02 16:39:50,085 ERROR [STDERR]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      2009-09-02 16:39:50,085 ERROR [STDERR]  at java.lang.reflect.Method.invoke(Method.java:585)
      2009-09-02 16:39:50,085 ERROR [STDERR]  at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
      2009-09-02 16:39:50,085 ERROR [STDERR]  at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
      2009-09-02 16:39:50,085 ERROR [STDERR]  at org.jboss.seam.async.AsynchronousInvocation$1.process(AsynchronousInvocation.java:62)
      2009-09-02 16:39:50,085 ERROR [STDERR]  at org.jboss.seam.async.Asynchronous$ContextualAsynchronousRequest.run(Asynchronous.java:80)
      2009-09-02 16:39:50,085 ERROR [STDERR]  at org.jboss.seam.async.AsynchronousInvocation.execute(AsynchronousInvocation.java:44)
      2009-09-02 16:39:50,085 ERROR [STDERR]  at org.jboss.seam.async.QuartzDispatcher$QuartzJob.execute(QuartzDispatcher.java:243)
      2009-09-02 16:39:50,085 ERROR [STDERR]  at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
      2009-09-02 16:39:50,085 ERROR [STDERR]  at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
      2009-09-02 16:39:50,086 ERROR [STDERR] Caused by: org.hibernate.SessionException: Session is closed!
      2009-09-02 16:39:50,086 ERROR [STDERR]  at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:72)
      2009-09-02 16:39:50,087 ERROR [STDERR]  at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1138)
      2009-09-02 16:39:50,087 ERROR [STDERR]  at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
      2009-09-02 16:39:50,087 ERROR [STDERR]  at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:67)
      2009-09-02 16:39:50,087 ERROR [STDERR]  ... 93 more
      



      I checked the session state when the exception occurs and:





      Session is connected, open and not dirty.


      The only way to execute it successfully again is restarting the AS.


      Any help is really appreciated.


      Regards,
      Raffaele Camanzo





        • 1. Re: Batch procedure (with BTM) works only once per server restart.
          Nikolay Elenkov Master

          Use @PersistenceContext EntityManager instead of @In EntityManager. The SMPC is bound to
          a conversation, and is probably closed when it expires. If you use @PersistenceContext, you
          will get a fresh (transaction-scoped) EntityManager on every execution.


          HTH

          • 2. Re: Batch procedure (with BTM) works only once per server restart.
            raffaele camanzo Newbie

            Hi Nikolay,


            first of all thank you for your reply!


            This was my first option, accordingly with Seam reference statement:



            If you are using EJB3 and mark your class or method @TransactionAttribute(REQUIRES_NEW)
            then the transaction and persistence context shouldn't be propagated to method calls on this
            object. However as the Seam-managed persistence context is propagated to any component
            within the conversation, it will be propagated to methods marked REQUIRES_NEW. Therefore,
            if you mark a method REQUIRES_NEW then you should access the entity manager using
            @PersistenceContext

            Unfortunately doing so my scheduler does not do the job at all (it fails also the first time with this exception):


            2009-09-03 09:56:19,063 DEBUG [org.quartz.simpl.SimpleJobFactory] Producing instance of Job 'DEFAULT.-47eded53:1237ee33de7:-7fff', class=org.jboss.seam.async.QuartzDispatcher$
            QuartzJob
            2009-09-03 09:56:19,075 DEBUG [org.quartz.core.JobRunShell] Calling execute on job DEFAULT.-47eded53:1237ee33de7:-7fff
            2009-09-03 09:56:19,078 DEBUG [org.jboss.seam.async.Asynchronous] executing: org.jboss.seam.async.AsynchronousInvocation$1@148b392
            2009-09-03 09:56:19,080 DEBUG [it.finservice.odino.core.OLog] |WS-or-TIMER| [StatisticheOperativeScheduler.schedule] <StatisticheOperativeTimer> ------>>  Inizio
            2009-09-03 09:56:19,113 DEBUG [it.finservice.odino.core.OLog] |WS-or-TIMER| [StatisticheOperativeManager.aggiornaDati] Stato della sessione. connesso: TRUE - aperto: TRUE - sp
            orco: FALSE
            2009-09-03 09:56:19,798 DEBUG [it.finservice.odino.core.OLog] |WS-or-TIMER| [StatisticheClienteManager.analizzaCliente] <StatisticheClienteManager> Inizializzazione statistica
             per cliente: AAAAA
            2009-09-03 09:56:19,809 DEBUG [it.finservice.odino.core.OLog] |WS-or-TIMER| [StatisticheClienteManager.analizzaCliente] <StatisticheClienteManager> Inizializzazione statistica
             per cliente: CLIENTE FINSERVICE 3
            2009-09-03 09:56:19,820 ERROR [org.jboss.ejb3.tx.BMTInterceptor] Application error: BMT stateless bean StatisticheClienteManager should complete transactions before returning
            (EJB3 13.6.1)
            2009-09-03 09:56:19,822 DEBUG [it.finservice.odino.core.OLog] |WS-or-TIMER| [StatisticheOperativeManager.aggiornaDati] Stato della sessione. connesso: TRUE - aperto: TRUE - sp
            orco: FALSE
            2009-09-03 09:56:19,822 ERROR [STDERR] javax.ejb.EJBException: Application error: BMT stateless bean StatisticheClienteManager should complete transactions before returning (E
            JB3 13.6.1)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at org.jboss.ejb3.tx.BMTInterceptor.checkStatelessDone(BMTInterceptor.java:182)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at org.jboss.ejb3.tx.BMTInterceptor.handleStateless(BMTInterceptor.java:76)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at org.jboss.ejb3.tx.BMTInterceptor.invoke(BMTInterceptor.java:131)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:214)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:184)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:81)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at $Proxy775.analizzaCliente(Unknown Source)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            2009-09-03 09:56:19,823 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at java.lang.reflect.Method.invoke(Method.java:585)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.javassist.tmp.java.lang.Object_$$_javassist_seam_8.analizzaCliente(Object_$$_javassist_seam_8.java)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at it.finservice.odino.scheduler.statisticheOperative.bean.StatisticheOperativeManager.aggiornaDati(StatisticheOperativeManager.java:88
            )
            2009-09-03 09:56:19,824 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at java.lang.reflect.Method.invoke(Method.java:585)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:30)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at java.lang.reflect.Method.invoke(Method.java:585)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.ejb3.tx.BMTInterceptor.handleStateless(BMTInterceptor.java:71)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.ejb3.tx.BMTInterceptor.invoke(BMTInterceptor.java:131)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            2009-09-03 09:56:19,824 ERROR [STDERR]  at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:214)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:184)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:81)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at $Proxy778.aggiornaDati(Unknown Source)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at java.lang.reflect.Method.invoke(Method.java:585)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.javassist.tmp.java.lang.Object_$$_javassist_seam_7.aggiornaDati(Object_$$_javassist_seam_7.java)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at it.finservice.odino.scheduler.statisticheOperative.StatisticheOperativeScheduler.schedule(StatisticheOperativeScheduler.java:74)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at java.lang.reflect.Method.invoke(Method.java:585)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.async.AsynchronousInterceptor.aroundInvoke(AsynchronousInterceptor.java:52)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at it.finservice.odino.scheduler.statisticheOperative.StatisticheOperativeScheduler_$$_javassist_seam_6.schedule(StatisticheOperativeSc
            heduler_$$_javassist_seam_6.java)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at java.lang.reflect.Method.invoke(Method.java:585)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.async.AsynchronousInvocation$1.process(AsynchronousInvocation.java:62)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.async.Asynchronous$ContextualAsynchronousRequest.run(Asynchronous.java:80)
            2009-09-03 09:56:19,825 ERROR [STDERR]  at org.jboss.seam.async.AsynchronousInvocation.execute(AsynchronousInvocation.java:44)
            2009-09-03 09:56:19,826 ERROR [STDERR]  at org.jboss.seam.async.QuartzDispatcher$QuartzJob.execute(QuartzDispatcher.java:243)
            2009-09-03 09:56:19,826 ERROR [STDERR]  at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
            2009-09-03 09:56:19,826 ERROR [STDERR]  at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
            2009-09-03 09:56:19,827 ERROR [STDERR] Caused by: javax.persistence.PersistenceException: org.hibernate.SessionException: Session is closed!
            2009-09-03 09:56:19,827 ERROR [STDERR]  at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
            2009-09-03 09:56:19,827 ERROR [STDERR]  at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:76)
            2009-09-03 09:56:19,827 ERROR [STDERR]  at it.finservice.odino.scheduler.statisticheOperative.bean.StatisticheClienteManager.caricaDebitori(StatisticheClienteManager.java:164)
            
            2009-09-03 09:56:19,827 ERROR [STDERR]  at it.finservice.odino.scheduler.statisticheOperative.bean.StatisticheClienteManager.analizzaCliente(StatisticheClienteManager.java:77)
            
            2009-09-03 09:56:19,828 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            2009-09-03 09:56:19,828 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            
            ...
            



            Printing out the session state:


            connected: TRUE
            open: TRUE
            dirty: FALSE


            but the exception cause is: javax.persistence.PersistenceException: org.hibernate.SessionException: Session is closed!


            Moreover setting @PersistenceContext annotation I don't see the server output for the SMPC creation; when I annotate the entityManager with @In instead I see in the server output (even when it fails...):




            2009-09-03 10:15:51,592 DEBUG [org.jboss.seam.persistence.ManagedPersistenceContext] created seam managed persistence context for persistence unit: java:/odinoSchedulerFlashEn
            tityManagerFactory



            Regards,


            Raffaele Camanzo

            • 3. Re: Batch procedure (with BTM) works only once per server restart.
              Nikolay Elenkov Master

              The error you are getting is for a different bean: StatisticheClienteManager. How is that one configured?


              Generally, if you use REQURIES_NEW and @PersistenceContext you can do the same thing without resorting to BMT.
              Say, call a REQUIRES_NEW method to process every 100 entries, that shouldn't cause transaction timeouts.


              2009-09-03 09:56:19,820 ERROR [org.jboss.ejb3.tx.BMTInterceptor] Application error: BMT stateless bean StatisticheClienteManager should complete transactions before returning
              (EJB3 13.6.1)
              

              • 4. Re: Batch procedure (with BTM) works only once per server restart.
                raffaele camanzo Newbie

                Hi Nikolay,


                the StatisticheClienteManager is another stateless configured the same as his caller.


                To avoid any possible problem about this indirection I removed it and moved all the source code in the caller stateless StatisticheOperativeManager.


                Then I tried with your approach:


                1- Removed the BMT annotation;


                2- Injected the entityManager as @PersistenceContext;


                3- Marked the method that does the dirty job as @TransactionAttribute(REQUIRES_NEW).


                Unfortunately also this configuration does not work; more clearly: REQUIRES_NEW annotation does not work at all, when the method returns no data is committed in the database and after a while the entityManager fails on transaction timeout.



                In any case, thank you for your time Nikolay.
                Regards,


                Raffaele Camanzo

                • 5. Re: Batch procedure (with BTM) works only once per server restart.
                  raffaele camanzo Newbie

                  Ok solved!


                  Really weird, it was a (stupid) programming error.


                  Into the stateless bean there was this declaration:


                  private static Query queryDebitori;
                  



                  used in this way:


                  @SuppressWarnings("unchecked")
                  private List<Debitore> caricaDebitori(ClienteFinservice cliente) {
                       if (queryDebitori == null) {
                            queryDebitori = entityManager.createQuery(QUERY_DEBITORI);
                       }
                       queryDebitori.setParameter("cliente", cliente.getCdClienteFinservice());
                       return queryDebitori.getResultList();
                  }
                  



                  Then:



                  • The first time everything was ok, the query object was consistent;




                  • Every further timer execution did generate an error because the query was related to a closed session (not the current one).




                  Sorry for wasting your time Nikolay.


                  Regards,


                  Raffaele Camanzo