cancel
Showing results for 
Search instead for 
Did you mean: 

MultiSchemaMultiTenantProcessEngineConfiguration transactionality

lucapinelli
Champ in-the-making
Champ in-the-making
Hello guys,

I'm adding the muti-tenancy support to an existing application. To do this I'm using the MultiSchemaMultiTenantProcessEngineConfiguration. The migration works fine except for the transactionality. In the previous version, using the SpringProcessEngineConfiguration, if an exception is thrown in an ActivitiEventListener the transaction is not committed while in the current version the transaction is committed. How can I set the transaction manager using the MultiSchemaMultiTenantProcessEngineConfiguration?
2 REPLIES 2

jbarrez
Star Contributor
Star Contributor
> if an exception is thrown in an ActivitiEventListener the transaction is not committed while in the current version the transaction is committed.

I would expect it always to roll back when an exception happens.

Can you post your listener code so I can understand what you're trying to do?

lucapinelli
Champ in-the-making
Champ in-the-making
Hi,
thanks for asking! Following a simplified version of the listener:

<java>
package com.activiti.transaction;

import java.sql.Connection;
import java.sql.Statement;

import org.activiti.engine.ActivitiException;
import org.activiti.engine.delegate.event.ActivitiEntityEvent;
import org.activiti.engine.delegate.event.ActivitiEvent;
import org.activiti.engine.delegate.event.ActivitiEventListener;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.task.Task;

public class TaskCreatedEventListener implements ActivitiEventListener {

@Override
public void onEvent(ActivitiEvent event) {
  try {
   Task task = (Task) ((ActivitiEntityEvent) event).getEntity();
   // save your custom data
   Connection conn = Context.getCommandContext().getDbSqlSession().getSqlSession().getConnection();
   try (Statement st = conn.createStatement()) {
    st.executeUpdate("insert into custom_table (task_id) values ('" + task.getId() + "')");
   }
   // do some check and raise an exception if something is wrong
   if (task.getName().startsWith("error_")) {
    throw new ActivitiException("Task creation blocked");
   }
  } catch (Exception e) {
   throw new RuntimeException(e);
  }
}

@Override
public boolean isFailOnException() {
  return true;
}

}
</java>