<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
timer 4.3 error
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/lamj1">Jas Lam</a> in <i>jBPM</i> - <a href="http://community.jboss.org/message/535918#535918">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>I modified the org.jbpm.examples.eventlistener jUnit test case slightly to introduce a timer as follow: the red code is the newly insert timer.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java"><?xml version=<font color="red">"1.0"</font> encoding=<font color="red">"UTF-8"</font>?>
 
<process name=<font color="red">"EventListener"</font> xmlns=<font color="red">"http://jbpm.org/4.2/jpdl"</font>>
  <on event=<font color="red">"start"</font>>
    <event-listener>
      <field name=<font color="red">"msg"</font>><string value=<font color="red">"start on process definition"</font>/></field>
    </event-listener>
  </on>
 
  <start g=<font color="red">"17,19,48,48"</font>>
    <transition to=<font color="red">"wait"</font>/>
  </start>
 
  <state name=<font color="red">"wait"</font> g=<font color="red">"96,16,104,52"</font>>
  <on event=<font color="red">"start"</font>>
   <event-listener>
        <field name=<font color="red">"msg"</font>><string value=<font color="red">"start on activity wait"</font>/></field>
   </event-listener>
  </on>
  <on event=<font color="red">"NotifyRCP"</font>>
      <timer duedate=<font color="red">"5 seconds"</font>/>
       <event-listener>
          <field name=<font color="red">"msg"</font>><string value=<font color="red">"NotifyRCP"</font>/></field>      
       </event-listener>     
    </on>     
 
    <on event=<font color="red">"end"</font>>
      <event-listener>
        <field name=<font color="red">"msg"</font>><string value=<font color="red">"end on activity wait"</font>/></field>
      </event-listener>
    </on>
 
    <transition to=<font color="red">"park"</font>>
      <event-listener>
        <field name=<font color="red">"msg"</font>><string value=<font color="red">"take transition"</font>/></field>
      </event-listener>
    </transition>
  </state>
  <state name=<font color="red">"park"</font> g=<font color="red">"231,19,80,52"</font>/>
 
</process>
 
 
 
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>In the test case i just add an additional text to the expectedLogs and a sleep</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> testEventListener() <font color="navy">{</font>
    ProcessInstance processInstance = executionService.startProcessInstanceByKey(<font color="red">"EventListener"</font>);
    List<String> expectedLogs = <font color="navy"><b>new</b></font> ArrayList<String>();
    expectedLogs.add(<font color="red">"start on process definition"</font>);
    expectedLogs.add(<font color="red">"start on activity wait"</font>);
    expectedLogs.add(<font color="red">"NotifyRCP"</font>);
    <font color="navy"><b>try</b></font><font color="navy">{</font> Thread.sleep(6000); <font color="navy">}</font> <font color="navy"><b>catch</b></font>(Exception e)<font color="navy">{</font><font color="navy">}</font>
 
    List<String> logs = (List<String>) executionService.getVariable(processInstance.getId(), <font color="red">"logs"</font>);
   
    assertEquals(expectedLogs, logs);
   
    Execution execution = processInstance.findActiveExecutionIn(<font color="red">"wait"</font>);   
    executionService.signalExecutionById(execution.getId());
   
    logs = (List<String>) executionService.getVariable(processInstance.getId(), <font color="red">"logs"</font>);
    expectedLogs.add(<font color="red">"end on activity wait"</font>);
    expectedLogs.add(<font color="red">"take transition"</font>);
   
    assertEquals(expectedLogs, logs);
  <font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>When I run this code the first time, it always work!!!! BUT after that I kept failing when the timer triggered!!!  with the following error trace. Could some one confirm this? i tried this on two separate machine and getting the same behavior. Full source code is attached. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code">15:09:12,216 FIN | [ExecuteActivity] execution[EventListener.50007.wait] executes activity(wait)
[start on process definition, start on activity wait]
15:09:12,232 FIN | [HibernateSessionResource] ----- committing hibernate tx 23511316 -------------------------------------------------------
15:09:12,240 FIN   | [HibernateSessionResource] ----- beginning hibernate tx 31798998 --------------------------------------------------------
15:09:12,241 FIN   | [HibernateSessionResource] ----- committing hibernate tx 32102833 -------------------------------------------------------
15:09:12,242 FIN   | [HibernateSessionResource] ----- beginning hibernate tx 22677439 --------------------------------------------------------
15:09:12,251 FIN   | [HibernateSessionResource] ----- committing hibernate tx 32700170 -------------------------------------------------------
15:09:17,210 FIN   | [HibernateSessionResource] ----- beginning hibernate tx 28678425 --------------------------------------------------------
### EXCEPTION ###########################################
15:09:17,217 SEV   | [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [org.jbpm.pvm.internal.job.TimerImpl#50012]
     at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1792)
     at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2435)
     at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2335)
     at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2635)
     at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:115)
     at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
     at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
     at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
     at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
     at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
     at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
     at org.jbpm.pvm.internal.tx.HibernateSessionResource.prepare(HibernateSessionResource.java:56)
     at org.jbpm.pvm.internal.tx.StandardTransaction.commit(StandardTransaction.java:107)
     at org.jbpm.pvm.internal.tx.StandardTransaction.complete(StandardTransaction.java:64)
     at org.jbpm.pvm.internal.tx.StandardTransactionInterceptor.execute(StandardTransactionInterceptor.java:61)
     at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.executeInNewEnvironment(EnvironmentInterceptor.java:53)
     at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:40)
     at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
     at org.jbpm.pvm.internal.svc.SkipInterceptor.execute(SkipInterceptor.java:43)
     at org.jbpm.pvm.internal.jobexecutor.DispatcherThread.acquireJobs(DispatcherThread.java:126)
     at org.jbpm.pvm.internal.jobexecutor.DispatcherThread.run(DispatcherThread.java:67)
### EXCEPTION ###########################################
15:09:17,219 FIN   | [HibernateSessionResource] ----- rolling back hibernate tx 28848200 -----------------------------------------------------
15:09:17,270 FIN   | [HibernateSessionResource] ----- beginning hibernate tx 1191324 --------------------------------------------------------
Thank you in advance.
</code></pre></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/535918#535918">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>