Calling method: saveModel() of act_re_model, throws ActivitiOptimisticLockingException when called from two different services having different transaction

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Member

Calling method: saveModel() of act_re_model, throws ActivitiOptimisticLockingException when called from two different services having different transaction

Hi,

Calling method: repositoryService.saveModel() of act_re_model, throws ActivitiOptimisticLockingException when it is called from two different Service layers having different transactions (there is no chance of Transaction being persisted).

I have calls to the method initiated from application to application, hence the previous transaction has to be committed.

But then the second call from application to application, redirected to Service layer and then calling this method, however throws the mentioned exception with below error:-

Optimistic locking exception : org.activiti.engine.ActivitiOptimisticLockingException: org.activiti.engine.impl.persistence.entity.ModelEntity@5c7a4bf8 was updated by another transaction concurrently

I have even tried to use NOT_SUPPORTED Spring propogation annotation on the method that makes first call to the saveModel() method and also REQUIRED and REQUIRES_NEW, but none works.

Even before the second call to saveModel() method, I have ensured that there is no lock acquired on ACT_RE_MODEL by previous databaseTransaction (when I called saveModel() for the first time, the dbTransaction is going to occur).

Any help will be appreciated.

Thanks,

Ami Dave

3 Replies
Highlighted
Established Member II

Re: Calling method: saveModel() of act_re_model, throws ActivitiOptimisticLockingException when called from two different services having different transaction

Hi Ami Dave,

Which Activiti version are you on?

Also, it would be easier for everybody if you can attach a unit test. This is important for people to spot where in your code that you are trying to access the same resource concurrently. Have you looked at the definition of this exception in Activiti? ActivitiOptimisticLockingException (Activiti - Engine 5.22.0 API) 

You said

I have calls to the method initiated from application to application, hence the previous transaction has to be committed.

But then the second call from application to application, redirected to Service layer and then calling this method, however throws the mentioned exception with below error:-

Are you sure that you are not calling 'saveModel' at the same time or concurrently? You know this has to be well-controlled by the application right?

Hope this helps,

Thong

 

Highlighted
Active Member

Re: Calling method: saveModel() of act_re_model, throws ActivitiOptimisticLockingException when called from two different services having different transaction

Hi,

Our current Activiti Framework Version is 5.15

Actually I feel it is easy to detremine that if I make a server-to-server (application-to-application) call then previous Transaction has to be committed. And I can see the changes in database tables, even I can't find any table is still locked after first call. 

Hence there is some issue from Activiti itself that it isn't committing the previous transaction of saveModel somwhow, I have tried to put delay of 3mins as well once first call is back to the initiator server, but still getting same Exception on second call to saveModel.

Is there any way to handle this situation?

Thanks,

Ami Dave

Highlighted
Established Member II

Re: Calling method: saveModel() of act_re_model, throws ActivitiOptimisticLockingException when called from two different services having different transaction

Hi Ami Dave ,

I don't quite understand your system topology when you said 'server-server (application-application)'. Can you describe your Activiti topology more clearly?

 

I have tried to put delay of 3mins as well once first call is back to the initiator server, but still getting same Exception on second call to saveModel.

Of course this doesn't solve the problem. This is very bad programming practice.

Unless I understand more about your setup and how to reproduce your issue (with a unit test), there's nothing I can do to help you. 

Cheers,

Thong Huynh