cancel
Showing results for 
Search instead for 
Did you mean: 

Activiti Spring Transaction Problem

innuendo80
Champ in-the-making
Champ in-the-making
Hi,

I'm new on Activiti and I'm studying it to evaluate it for my company.

I'm trying a simple demo with Spring MVC and I'm interested in managing transactions between activiti and my business logic.

The problem is that the transactional methods don't get rolled back when something (the activiti complete task or the insert into my dao) throws exception.

This is my applicationContext.xml:

<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
       <property name="driverClass" value="com.mysql.jdbc.Driver" />
       <property name="url" value="jdbc:mysql://localhost:3306/activiti" />
       <property name="username" value="root" />
       <property name="password" value="password" />
  </bean>

  <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
  </bean>

<bean id="processEngineConfiguration"
      class="org.activiti.spring.SpringProcessEngineConfiguration">
      <property name="dataSource" ref="dataSource" />
      <property name="transactionManager" ref="transactionManager" />
      <property name="databaseSchemaUpdate" value="true" />
      <property name="jobExecutorActivate" value="false" />
       <property name="deploymentResources" value="classpath*:/demoprocess.bpmn20.xml" />     
   </bean>
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
        <property name="processEngineConfiguration" ref="processEngineConfiguration" />
   </bean>

<tx:annotation-driven transaction-manager="transactionManager" />
 
  <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
  <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
  <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
  <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
  <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />


This is my Service:


@Service
public class BOProcess {

   @Autowired
   private RuntimeService runtimeService;
   
   @Autowired
   private TaskService taskService;
   
   @Autowired
   private DAOMyTab daoMyTab;
   
   protected final static Logger logger = Logger.getLogger(BOProcess.class);

   @Transactional
   public void start(){
      
      
      logger.info("Entering start method….");
      
      ProcessInstance pi = runtimeService.startProcessInstanceByKey("activitiDemo");
      
      logger.info("Started Process instance id: " + pi.getProcessInstanceId());
      
      daoMyTab.insert("PROCESS INSTANCE ID STARTED: " + pi.getProcessInstanceId());
      

      logger.info("Finish");
      
   }
   

   @Transactional
   public void completeTask(String taskId){
      
      logger.info("Entering completeTask method….");
      
      
      logger.info("TASK ID: " + taskId);
      
      
      taskService.complete(taskId);
      
      daoMyTab.insert(taskId);
      
      logger.info("Finish");
      
   }   
}

And the Repository:


@Repository
public class DAOMyTab {

   @Autowired
   private DataSource dataSource;

   public void insert(String value){
      
      JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
      
      String query = "insert into activiti.mytab(valore) values('" + value + "')";
      
      jdbcTemplate.update(query);
      
   }
   
public void insertError(String value) throws Exception{
         throw new Exception("ERRORE");      
   }
}

Thanks for your help.
1 REPLY 1

jbarrez
Star Contributor
Star Contributor
I tried your config, but it works here perfectly: I'm getting

Started Process instance id: 7504
Exception in thread "main" org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [insert into activiti.mytab(valore) values …


And when I check ACT_RU_EXECUTION, no rows are found, so the rollback is working as it should.