0
votes

I want to test the integration of Spring and Activiti, then I stuck with confusing problem. I have a workflow with 2 service task (using jpa repository saveAndFlush method to update database) A and B

In the service A, I actively throw a new Exception , then the transaction rollbacks, and the flow stops. Well, it's okay.

However, how can I rollback the service A only and the flow continue to service B? Because if service A throws Exception, the flow will be stopped, and if Exception is caught ( then the flow continues), service A will not rollback.

I use JPA Repository to automatically handle transaction, so change to manual mode will take a lot of efforts now.

2

2 Answers

0
votes

Probably you need a new transaction for every service in the flow and catch all exception.

0
votes

Put a layer between your service tasks A,B and your process, let's make its name TransactionService. This service should trigger your service methods. Also those service methods should use new transactions for their operations(you can use @Transactional annotation). In TransactionService don't do anything, just trigger them and wrap them in try catch blocks.
As a result of them you can catch the exception and make it flow to the next task and doesn't care about rollback because after an exception it will be rolled back automatically.