cancel
Showing results for 
Search instead for 
Did you mean: 

Unexpected behaviour of Activiti Engine with using Spring JTA transaction

savanladani
Champ in-the-making
Champ in-the-making
Overview:

I have Service Task (Java Delegate), which calls my custom Spring Service, which has Spring Annotated Transaction with Propogation.REQUIRED. (See EmpDetailService.java)

Scenario 1: After completing "Emp Details 1" task control goes to "Emp Details 1 Service(Java Delegates)" service task which calls  custom DB service to persist data into custom tables.
now while I throw exception explicitly in service task than "Emp Details 1" task don't complete (not data insert, update, and delete in Activiti tables) and no data gets persisted in my custom tables which is expected behaviour.

Scenario 2: After completing "Emp Details 1" task control goes to "Emp Details 1 Service(Java Delegates)" service task which calls  custom DB service to persist data into custom tables. In this scenario I am explicitly setting null (NOT NULL in DATABASE )  value in custom table, So while inserting/updating a record Hibernate throws exception (org.hibernate.exception.ConstraintViolationException: Column 'FIRST_NAME' cannot be null) , but surprisingly this time "Emp Details 1" task gets completed and no data gets persisted in custom tables.

So, in nutshell difference between both the scenarios is that in Scenario 1 I am throwing exception explicitly and in Scenario 2 I get exception from underlying Persistence layer.
Question:
I am unable to understand that why in Scenario 2 task gets completed even though exception is being thrown by hibernate in "Emp Details 1 Service"

I have also attached error_log.txt and my activiti configuration file and spring service class.
1 REPLY 1

trademak
Star Contributor
Star Contributor
But in the example Java file you've attached you catch the exception, so the data insert might have failed, but the Activiti Engine will continue with completing the task. If this is not the desired behaviour I think you should not catch the exception in the service task or rethrow it.

Best regards,