03-28-2013 09:09 AM
@Test
@Rollback(value = false)
public void testTaskWorkFlowServiceTran() throws Exception {
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("var1", "value1");
TaskEntity task = new TaskEntity();
task.setName("name");
task.setDescription("desc");
task.setPriority(60);
task.setDueDate(Calendar.getInstance().getTime());
task.setOwner("owner");
task.setAssignee("assignee");
taskTestService.createTask(task, vars);
}
@Service
@Transactional
public class TaskTestService {
@Autowired
private TaskService taskService;
public void createTask(TaskEntity taskEntity, Map<String, Object> vars) throws Exception {
Task task = taskService.newTask();
task.setName(taskEntity.getName());
task.setDescription(taskEntity.getDescription());
task.setPriority(taskEntity.getPriority());
task.setDueDate(taskEntity.getDueDate());
task.setOwner(taskEntity.getOwner());
task.setAssignee(taskEntity.getAssignee());
taskService.saveTask(task);
if (vars != null) {
throw new Exception("boom!");
} else {
taskService.setVariables(task.getId(), vars);
}
}
}
<context:component-scan base-package="ru.nti.siu.bpm.test" />
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="databaseType" value="postgres" />
<property name="dataSource" ref="myDataSource" />
<property name="transactionManager" ref="myTransactionManager" />
<property name="databaseSchemaUpdate" value="false" />
<property name="history" value="full" />
<property name="jobExecutorActivate" value="false" />
<property name="idGenerator">
<bean class="org.activiti.engine.impl.persistence.StrongUuidGenerator" />
</property>
</bean>
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>
<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" />
<bean id="identityService" factory-bean="processEngine"
factory-method="getIdentityService" />
<bean id="myTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="myDataSource" />
</bean>
<bean id="myDataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<property name="driverClass" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://192.168.1.1/mydatabase" />
<property name="username" value="postgres" />
<property name="password" value="postgres" />
</bean>
03-28-2013 09:11 AM
<tx:annotation-driven/>
03-28-2013 10:12 AM
<context:component-scan base-package="ru.nti.siu.bpm.test" />
<bean id="myDataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<property name="driverClass" value="org.postgresql.Driver" />
<property name="url" value="jdbcostgresql://192.168.1.1/mydatabase" />
<property name="username" value="postgres" />
<property name="password" value="postgres" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="myDataSource" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="databaseType" value="postgres" />
<property name="dataSource" ref="myDataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="databaseSchemaUpdate" value="false" />
<property name="history" value="full" />
<property name="jobExecutorActivate" value="false" />
<property name="idGenerator">
<bean class="org.activiti.engine.impl.persistence.StrongUuidGenerator" />
</property>
</bean>
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>
<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" />
<bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />
03-28-2013 10:22 AM
03-29-2013 09:30 AM
03-29-2013 01:45 PM
Sorry for the late reply, posted the draft on DropBox.
package ru.dikma;
import java.util.Map;
import org.activiti.engine.TaskService;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Service("TestTaskService")
public class TestTaskService {
@Autowired
private TaskService taskService;
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void createTask(TaskEntity taskEntity, Map<String, Object> vars)
throws Exception {
Task task = taskService.newTask();
task.setName(taskEntity.getName());
task.setDescription(taskEntity.getDescription());
task.setPriority(taskEntity.getPriority());
task.setDueDate(taskEntity.getDueDate());
task.setOwner(taskEntity.getOwner());
task.setAssignee(taskEntity.getAssignee());
taskService.saveTask(task);
if (vars != null) {
throw new Exception("boom!");
} else {
taskService.setVariables(task.getId(), vars);
}
}
}
04-01-2013 04:58 AM
04-01-2013 04:35 PM
You do not understand my question, it is expected that if between a call to save the task and save the variables exception occurs then the problem will not be saved, but it is not, although the method is declared as transactional. Check it out, they are two different transactions. How to configure the service, these two methods were in the same transaction?i well understand your problem, in your case is simpler to avoid exception throwing between save of task and "save" the variables :twisted: (i assume, that mybatis + own activiti implementation would be root of problem)
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.