Question about some operations in a executionListener
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2014 03:16 AM
@Transactional @Component("myServiceBean") public MyServiceBean{ }
public void doSomething() throws RuntimeException{ taskService.complete("101"); }
My process definition has a executionListener, when some tasks complete, it will be fired, My listener like this:
@Transactional @Component("CaseAcceptEndListener") public class CaseAcceptEndListener implements ExecutionListener{ @Override public void notify(DelegateExecution delegateexecution) throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myKey"); HistoricProcessInstance hp = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()) .singleResult(); } }
In my listener, at first I start a another process, and then I query a historicProcessInstance by the process id just happended. but something is wrong, because I can't find the historyProcess. it seems like the codes in different transaction.
use the same code(notify code) in my unit test, I can find the historyProcess, like this:
@Test public void test(){ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myKey"); HistoricProcessInstance hp = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()) .singleResult(); }
so, can you give me some advices? thanks very much
- Labels:
-
Archive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2014 05:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2014 05:29 AM
<code>
<extensionElements>
<activiti:executionListener event="end" delegateExpression="${myListener}"></activiti:executionListener>
</extensionElements>
</code>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2014 05:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2014 03:57 AM
Could it be the historic process instance simply isn't flushed to the database yet? Activiti only flushes at the end of the transaction.
Wehere in the process is this execution listener firing?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2014 10:06 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2014 08:38 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2014 03:53 AM
There is (dbSqlSession.flush), but it's still at the end of the transaction that it's committed. But it might work.
It does sounds strange the unit test can find it. Do you also use JTA in the unit test?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2014 10:13 PM
when it stepped over the code of the unit test at the line below:
<java>
String processInstanceId = runtimeService.startProcessInstanceByKey("t").getId();
</java>
it will flush:
<java>
//invode dbSqlSession's flush method
</java>
but if in the listener, it didn't happen.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2014 10:41 PM
<code>
2014-06-05 10:40 main DEBUG- — starting StartProcessInstanceCmd ——————————————————–
2014-06-05 10:40 main DEBUG- Running command with propagation REQUIRED
2014-06-05 10:40 main DEBUG- getCompositeTransaction() returning instance with id 192.168.0.121.tm0001100119
2014-06-05 10:40 main DEBUG- getCompositeTransaction() returning instance with id 192.168.0.121.tm0001100119
2014-06-05 10:40 main DEBUG- Participating in existing transaction
2014-06-05 10:40 main DEBUG- Valid context found. Reusing it for the current command 'org.activiti.engine.impl.cmd.StartProcessInstanceCmd'
2014-06-05 10:40 main DEBUG- getCompositeTransaction() returning instance with id 192.168.0.121.tm0001100119
2014-06-05 10:40 main INFO- atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@4b5011: calling toString…
2014-06-05 10:40 main DEBUG- atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@4b5011: toString returning com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@4b5011
2014-06-05 10:40 main DEBUG- ooo Using Connection [Transaction-aware proxy for target Connection [com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@4b5011]]
2014-06-05 10:40 main DEBUG- ==> Preparing: select * from ACT_RE_PROCDEF where KEY_ = ? and (TENANT_ID_ = '' or TENANT_ID_ is null) and VERSION_ = (select max(VERSION_) from ACT_RE_PROCDEF where KEY_ = ? and (TENANT_ID_ = '' or TENANT_ID_ is null))
2014-06-05 10:40 main DEBUG- getCompositeTransaction() returning instance with id 192.168.0.121.tm0001100119
2014-06-05 10:40 main DEBUG- atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@4b5011: notifyBeforeUse a SessionHandleState with 1 context(s)
2014-06-05 10:40 main DEBUG- getCompositeTransaction() returning instance with id 192.168.0.121.tm0001100119
2014-06-05 10:40 main DEBUG- a SessionHandleState with 1 context(s): checking XA context for transaction com.atomikos.icatch.imp.CompositeTransactionImp@f632fc7d
2014-06-05 10:40 main DEBUG- a TransactionContext: changing to state null
2014-06-05 10:40 main DEBUG- atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@4b5011: detected transaction com.atomikos.icatch.imp.CompositeTransactionImp@f632fc7d
2014-06-05 10:40 main DEBUG- Coordinator 192.168.0.121.tm0001100119 entering state: ACTIVE
2014-06-05 10:40 main INFO- registerSynchronization ( com.atomikos.jdbc.AtomikosConnectionProxy$JdbcRequeueSynchronization@f632fc7d ) for transaction 192.168.0.121.tm0001100119
2014-06-05 10:40 main INFO- atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@4b5011: calling prepareStatement…
2014-06-05 10:40 main DEBUG- atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@4b5011: prepareStatement returning com.mysql.jdbc.jdbc2.optional.JDBC4PreparedStatementWrapper@18169e8
2014-06-05 10:40 main DEBUG- ==> Parameters: t(String), t(String)
2014-06-05 10:40 main DEBUG- <== Total: 1
2014-06-05 10:40 main DEBUG- initializing ProcessInstance[3802]
2014-06-05 10:40 main DEBUG- Current history level: AUDIT, level required: ACTIVITY
2014-06-05 10:40 main DEBUG- ProcessInstance[3802] executes Activity(startevent1): org.activiti.engine.impl.bpmn.behavior.NoneStartEventActivityBehavior
2014-06-05 10:40 main DEBUG- Leaving activity 'startevent1'
2014-06-05 10:40 main DEBUG- Current history level: AUDIT, level required: ACTIVITY
2014-06-05 10:40 main DEBUG- ProcessInstance[3802] takes transition (startevent1)–flow1–>(usertask1)
2014-06-05 10:40 main DEBUG- Current history level: AUDIT, level required: ACTIVITY
2014-06-05 10:40 main DEBUG- ProcessInstance[3802] executes Activity(usertask1): org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior
2014-06-05 10:40 main DEBUG- Current history level: AUDIT, level required: AUDIT
2014-06-05 10:40 main DEBUG- Current history level: AUDIT, level required: AUDIT
2014-06-05 10:40 main DEBUG- Current history level: AUDIT, level required: AUDIT
2014-06-05 10:40 main DEBUG- Current history level: AUDIT, level required: AUDIT
2014-06-05 10:40 main DEBUG- Current history level: AUDIT, level required: AUDIT
2014-06-05 10:40 main DEBUG- getCompositeTransaction() returning instance with id 192.168.0.121.tm0001100119
2014-06-05 10:40 main INFO- atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@4b5011: calling toString…
2014-06-05 10:40 main DEBUG- atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@4b5011: toString returning com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@4b5011
2014-06-05 10:40 main DEBUG- ooo Using Connection [Transaction-aware proxy for target Connection [com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@4b5011]]
2014-06-05 10:40 main DEBUG- ==> Preparing: select * from ACT_RU_IDENTITYLINK where PROC_INST_ID_ = ?
2014-06-05 10:40 main DEBUG- getCompositeTransaction() returning instance with id 192.168.0.121.tm0001100119
2014-06-05 10:40 main DEBUG- atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@4b5011: notifyBeforeUse a SessionHandleState with 1 context(s)
2014-06-05 10:40 main DEBUG- getCompositeTransaction() returning instance with id 192.168.0.121.tm0001100119
2014-06-05 10:40 main DEBUG- a SessionHandleState with 1 context(s): checking XA context for transaction com.atomikos.icatch.imp.CompositeTransactionImp@f632fc7d
2014-06-05 10:40 main DEBUG- a TransactionContext: changing to state null
2014-06-05 10:40 main DEBUG- atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@4b5011: detected transaction com.atomikos.icatch.imp.CompositeTransactionImp@f632fc7d
2014-06-05 10:40 main DEBUG- Coordinator 192.168.0.121.tm0001100119 entering state: ACTIVE
2014-06-05 10:40 main INFO- registerSynchronization ( com.atomikos.jdbc.AtomikosConnectionProxy$JdbcRequeueSynchronization@f632fc7d ) for transaction 192.168.0.121.tm0001100119
2014-06-05 10:40 main INFO- atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@4b5011: calling prepareStatement…
2014-06-05 10:40 main DEBUG- atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@4b5011: prepareStatement returning com.mysql.jdbc.jdbc2.optional.JDBC4PreparedStatementWrapper@9eddf9
2014-06-05 10:40 main DEBUG- ==> Parameters: 3802(String)
2014-06-05 10:40 main DEBUG- <== Total: 0
2014-06-05 10:40 main DEBUG- Current history level: AUDIT, level required: AUDIT
2014-06-05 10:40 main DEBUG- Current history level: AUDIT, level required: ACTIVITY
2014-06-05 10:40 main DEBUG- — StartProcessInstanceCmd finished ——————————————————–
<code>
