0 Replies Latest reply on Apr 25, 2014 1:28 PM by baddeley84

    Commit transaction mid-method from EJB @MessageDriven

    baddeley84

      Hi,

       

      I have a long running process which runs inside a Seam component that takes about 60sec to complete, to allow its progress to be displayed I write to the database during its execution.

      When the process is invoked from a JAXRS bean the process works fine and the database is getting updated instantly

      But when the processing is invoked from a Quartz scheduled job (using a @MessageDriven) the updates only appear in the database once the method completes

      Can somebody explain the reason behind this and is there anyway around it? I have tried adding @TransactionAttribute(REQUIRES_NEW) to the MDB but this doesn't have any effect

      This is running on SEAM 2.2.2 and I am using a SMPC

      The scheduled task looks like this...

      @Name("minuteActions")

      @MessageDriven(

           activationConfig = {

                @ActivationConfigProperty(propertyName = "cronTrigger", propertyValue = "11 * * * * ?")

           }

      )

      @ResourceAdapter("quartz-ra.rar")

      @Depends({"jboss.web.deployment:war=processor/"})

      public class MinuteActions implements Job{

       

           @Logger private Log log;

           @In private ProcessSession processSession;

       

           public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException{

                processSession.processNewSession();

           }

      }

      And this is the processing (Seam) bean

      @AutoCreate

      @Name("processSession")

      public class ProcessSession{

           @Logger private Log log;

           @In private SessionDAO sessionDAO;

           public ProcessingRun processNewSession(Session session){

                session.setProcessingStartTime(new Date());

                sessionDAO.persist(session);

                //Some long running processing ~60sec

                session.setProcessingEndTime(new Date());

                sessionDAO.persist(session);

           }

      }

      Ps. also posted on StackOverflow: http://stackoverflow.com/questions/23280298/ejb-mdb-cannot-persist-data-mid-method