2 Replies Latest reply on Nov 21, 2005 6:14 PM by juan de la rosa

    Creating a timer dynamically in an ActionHandler fired by a

    LANNOY Christophe Newbie

      Hello,

      I 'am trying to create a timer dynamically in an ActionHandler fired by a timer (SchedulerThread) :

      I made the test :

      <task-node name="task6">
       <task name="task6" >
       <assignment class="MyTaskAssignementHandler">
       <actorId>acteur32</actorId>
       </assignment>
      
       <timer name="timertask6" duedate="3 minutes" >
       <action class="MyActionHandler" config-type="field" >
       </action>
       </timer>
      
       </task>
      
       <transition name="tr1" to="task7"></transition>
      </task-node>
      





      * first case

      code of MyActionHandler


      public void execute(ExecutionContext executionContext) throws Exception
       {
       .
       .
       .
      
       CreateTimerAction cta = new CreateTimerAction();
      
       cta.setDueDate("5 minutes");
       cta.setTimerName("timerCreeManuelement");
       cta.setTransitionName("tr1");
      
       cta.execute(executionContext);
      
       }


      When timer is fired on task6 the goal of MyActionHandler is to do some alert (mail by example, reassign task...) and then create a new Timer (I need a different timer from the first one, to execute a different action by example, it's why I dont use a repeat on first Timer)

      MyActionHandler is executed but the timer is not persisted

      I found the answer here :
      http://www.jboss.com/index.html?module=bb&op=viewtopic&t=67029
      With this patch the persistence is OK, but the entry created in table JBPM_TIMER does not contains value in attribute : GRAPHELEMENTTYPE_ and GRAPHELEMENT_ , because executionContext.getEventSource() return null (is it a bug ?) , the link with the task is not made -> when I end the task "task6" this timer is not deleted.

      * second case

      it's the same process but the code of MyActionHandler is :


      public void execute(ExecutionContext executionContext) throws Exception
       {
       .
       .
       .
      
       Delegation actionDelegation = new Delegation();
       actionDelegation.setClassName("MyActionHandler2");
       actionDelegation.setConfigType("field");
      
      
       Action action = new Action();
       action.setActionDelegation(actionDelegation);
      
      
       CreateTimerAction cta = new CreateTimerAction();
      
       cta.setDueDate("5 minutes");
       cta.setTimerName("timerCreeManuelement2");
      
       cta.setTimerAction(action);
      
       cta.execute(executionContext);
      
       }


      It's the same as case one but the action of the new timer is delegated to MyActionHandler2.

      The first timer is fired but I get an exception :

      4 nov. 2005 09:38:03 org.jbpm.db.JbpmSession commitTransaction
      GRAVE: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org.jbpm.graph.def.Action
      4 nov. 2005 09:38:03 org.jbpm.scheduler.impl.SchedulerThread run
      INFO: runtime exception while executing timers
      java.lang.RuntimeException: couldn't commit transaction
       at org.jbpm.db.JbpmSession.commitTransaction(JbpmSession.java:107)
       at org.jbpm.db.JbpmSession.commitTransactionAndClose(JbpmSession.java:129)
       at org.jbpm.scheduler.impl.SchedulerThread.executeTimers(SchedulerThread.java:131)
       at org.jbpm.scheduler.impl.SchedulerThread.run(SchedulerThread.java:35)
      Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org.jbpm.graph.def.Action
       at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
       at org.hibernate.type.EntityType.getIdentifier(EntityType.java:99)
       at org.hibernate.type.EntityType.isDirty(EntityType.java:216)
       at org.hibernate.type.TypeFactory.findDirty(TypeFactory.java:412)
       at org.hibernate.persister.entity.BasicEntityPersister.findDirty(BasicEntityPersister.java:2538)
       at org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:344)
       at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:108)
       at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:190)
       at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:70)
       at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
       at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
       at org.jbpm.db.JbpmSession.commitTransaction(JbpmSession.java:102)
       ... 3 more


      The Action for the delegation is not persisted

      Is it possible to do this sort of things (this two cases) ?

      Thanks for your interest.