cancel
Showing results for 
Search instead for 
Did you mean: 

Activiti and JTA transactions

gizmo1177
Champ in-the-making
Champ in-the-making
I have a question regard transactions and the activiti workflow. Here is the description of my problem:

We get a request from a external system. Within the request processor we start a new transaction, create our entities AND Start deployed activiti processes. My problem is that the processes starts directly after calling the start function in the activiti engine. The engine will not wait for the transaction to commit.

I´ve expected the following:
1. Start transaction within out logic
2. Create entities that belong to the process
3. Tell the engine to start a activiti process(Write process instance stuff in db)
4. Transaction commit.

–> Now the activiti process should with its first activiti. With this engine configuration activiti commits its data with MY transaction, but the process execution starts immediately after starting the process.

CdiJtaProcessEngineConfiguration config = new CdiJtaProcessEngineConfiguration();
            config.setTransactionManager(getTransactionManager());
            config.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
            config.setTransactionsExternallyManaged(true);
            config.setDataSourceJndiName("openejb:Resource/xxx");
            config.setEnableProcessDefinitionInfoCache(true);
            config.setAsyncExecutorEnabled(true);
            config.setAsyncExecutorActivate(true);
            config.setPostBpmnParseHandlers(Arrays.asList(new CdiEventSupportBpmnParseHandler()));
//            EntityManagerFactory emf = Persistence.createEntityManagerFactory("xxx");
//            config.setJpaEntityManagerFactory(emf);
            config.setJpaHandleTransaction(false);
            config.setJpaCloseEntityManager(false);

Some hints?
1 REPLY 1

gizmo1177
Champ in-the-making
Champ in-the-making
Some more info:
With this code my problem is solved.

// Persist the workflow (In this step I merge our workflow instance)
workflow = jpa.merge(workflow);
// Start process(In this step I start the process in activiti and store the processInstanceId of the activiti process in my data)
processHandler.startWorkflow(workflow);
// Store the workflow again(with processInstanceId of activiti)
workflow= jpa.merge(workflow);

I´m not sure if this is a proper way. With this approach my stored workfow instance is seen within the activiti process (but it is not committed yet).