org.camunda.bpm.engine.ProcessEngineException: Query return 2 results instead of max 1

Reference : Accessing the retry attempt for a failedJobRetryTimeCycle config during execution

I am using the query below to fetch the number of retries for a service task

var retriesNumber = execution.getProcessEngineServices().getManagementService()
.createJobQuery()
.activityId(execution.getCurrentActivityId())
.singleResult()
.getRetries();

However, in a multi-instance loop I get the exception as below when creating incident :

org.camunda.bpm.engine.ProcessEngineException: Query return 2 results instead of max 1
at org.camunda.bpm.engine.impl.AbstractQuery.executeSingleResult(AbstractQuery.java:211)
at org.camunda.bpm.engine.impl.AbstractQuery.execute(AbstractQuery.java:167)
at org.camunda.bpm.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:104)
at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:66)
at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30)
at org.camunda.bpm.engine.impl.AbstractQuery.singleResult(AbstractQuery.java:130)
at com

How to fix this query for multi-instance?

Hello my friend!

You must filter by processInstanceId in addition to ActivityId.

execution.getProcessEngineServices().getManagementService().createJobQuery()
.activityId(execution.getCurrentActivityId())
.processInstanceId(execution.getProcessInstanceId())
.singleResult()
.getRetries();

I hope this helps!

William Robert Alves

Hi William, even after using the below

int retryNumber = execution.getProcessEngineServices().getManagementService()
.createJobQuery()
.activityId(execution.getCurrentActivityId())
.processInstanceId(execution.getProcessInstanceId())
.singleResult()
.getRetries();

I still get the same exception for a multi-instance error.

Hi @Rad ,

could you please try to filter by activity id and execution id instead of the process instance id?


int retryNumber = execution.getProcessEngineServices().getManagementService()
.createJobQuery()
.activityId(execution.getCurrentActivityId())
.executionId(execution.getId())
.singleResult()
.getRetries();

Tho, I was not able to verify as I am on mobile currently.

Kind regards
Adagatiya

I have added it but this only happens when I see a error path, so I am not able to verify immediately.

1 Like

This seems to work

1 Like