External transaction management

I’m using flowable embedded in a web application using tomcat. In this web application i’m using atomikos and hibernate. Transactions are managed by this application and flowable code is executed inside existing transactions.

I tried to use JtaProcessEngineConfiguration and i have debug execute method from JtaTransactionInterceptor to confirm that existing transaction is used and is not creating new ones.

I tried to start a new process in flowable and I’m testing abort transaction after flowable code but workflow is initiated.

Example:

public void start(…) {
tx.start();
runtimeService.startProcessInstanceByKey(…);
tx.rollback();

}

Checked:

  1. Executing StartProcessInstanceCmd
    1.1 org.flowable.common.engine.impl.interceptor.CommandContextInterceptor is executing commandContext.close() which execute flushSessions from org.flowable.common.engine.impl.interceptor.CommandContext
    1.2 doCommit method from JtaTransactionInterceptor is not executed (but it does not matter because DbSqlSession already “committed”)
    1.3 It seams that DbSqlSession is not using transaction?

But, for instance, GetNextIdBlockCmd that is used to get next block of db ids is interacting properly with transaction manager:

  • It suspends existing transaction
  • Begin and commit a new one to increment db id
  • Resumes previous transaction

Do you have any ideas or any working test to check? I have checked existing topics and for instance Transaction management with interacting multiple applications but could not found any answer.

Thanks in advance.

I was not using AtomikosDataSourceBean as flowable datasource. I was using a MysqlXADataSource directly.

After i change to this everything is working ok.

<bean id="dbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:comp/env/jdbc/resouce-name" />
  </bean>

  <bean id="dataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean">
    <property name="xaDataSource" ref="dbDataSource" />
    <property name="uniqueResourceName" value="c1-workflow-db-ads" />
    <property name="borrowConnectionTimeout" value="30000" />
    <property name="minPoolSize" value="1" />
    <property name="poolSize" value="10" />
    <property name="maxPoolSize" value="15" />
  </bean>

<bean id="processEngineConfiguration" ....
   <property name="dataSource" ref="dataSource" />
</bean>

I still have problems in async executor.

I’m always getting “JTA transaction already completed - probably rolled back”. Any ideas?

org.springframework.transaction.UnexpectedRollbackException: JTA transaction already completed - probably rolled back
at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1018)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:746)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:714)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:152)
at org.flowable.common.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:46)
at org.flowable.common.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30)
at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:56)
at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:51)
at org.flowable.job.service.impl.asyncexecutor.ExecuteAsyncRunnable.executeJob(ExecuteAsyncRunnable.java:128)
at org.flowable.job.service.impl.asyncexecutor.ExecuteAsyncRunnable.run(ExecuteAsyncRunnable.java:116)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

Thanks in advance.

Async executor was invoking a custom FlowableEventListener that was closing connection :frowning_face:.

After fixing that, everything is working properly.