Unable to delete a process definition having more than one published version

Hi,
I am using camunda rest service call to delete a particular process definition. It takes care of it’s deployments as well. If there are deployments it’ll delete those too. But while trying to do so it’s running into following error :

org.camunda.bpm.engine.context - ENGINE-16004 Exception while closing command context: Expected one result (or null) to be returned by selectOne(), but found: 3
org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 3
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:81)
at org.camunda.bpm.engine.impl.db.sql.DbSqlSession.selectOne(DbSqlSession.java:117)
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.selectOne(DbEntityManager.java:188)
at org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionManager.findLatestProcessDefinitionByKeyAndTenantId(ProcessDefinitionManager.java:93)
at org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionManager.findLatestDefinitionByKeyAndTenantId(ProcessDefinitionManager.java:408)
at org.camunda.bpm.engine.impl.cmd.DeleteProcessDefinitionsByIdsCmd.isLatestProcessDefinition(DeleteProcessDefinitionsByIdsCmd.java:166)
at org.camunda.bpm.engine.impl.cmd.DeleteProcessDefinitionsByIdsCmd.findNewLatestProcessDefinition(DeleteProcessDefinitionsByIdsCmd.java:147)
at org.camunda.bpm.engine.impl.cmd.DeleteProcessDefinitionsByIdsCmd.deleteProcessDefinitions(DeleteProcessDefinitionsByIdsCmd.java:181)
at org.camunda.bpm.engine.impl.cmd.DeleteProcessDefinitionsByIdsCmd.execute(DeleteProcessDefinitionsByIdsCmd.java:100)
at org.camunda.bpm.engine.impl.persistence.entity.DeploymentManager$1.call(DeploymentManager.java:119)
at org.camunda.bpm.engine.impl.persistence.entity.DeploymentManager$1.call(DeploymentManager.java:111)
at org.camunda.bpm.engine.impl.interceptor.CommandContext.runWithoutAuthorization(CommandContext.java:477)
at org.camunda.bpm.engine.impl.persistence.entity.DeploymentManager.deleteDeployment(DeploymentManager.java:111)
at org.camunda.bpm.engine.impl.cmd.DeleteDeploymentCmd.execute(DeleteDeploymentCmd.java:75)
at org.camunda.bpm.engine.impl.cmd.DeleteDeploymentCmd.execute(DeleteDeploymentCmd.java:43)
at org.camunda.bpm.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:27)
at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:106)
at org.camunda.bpm.engine.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:45)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
at org.camunda.bpm.engine.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:43)
at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:69)
at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:32)
at org.camunda.bpm.engine.impl.RepositoryServiceImpl.deleteDeployment(RepositoryServiceImpl.java:122)
at org.camunda.bpm.engine.rest.sub.repository.impl.DeploymentResourceImpl.deleteDeployment(DeploymentResourceImpl.java:151)

This call works fine if it has only one published version. Can anybody help me in this ??

Hi @abhinay_pandey,

it seems that you are calling an API that expects to find only one (or zero) matches to perform an operation on. Those queries throw an error when more than one result was returned.

If you provided the code that you tried, it would be much easier to help you here. :slight_smile:

Cheers,
Miklas

Hi Miklas,
Here is code snippet which does the deletion

@DELETE
@Path("/{name}/deployment/{id}")
public void deleteDeployment(@Context UriInfo uriInfo, @PathParam(“id”) String deploymentId, @PathParam(“name”) String engineName) {
getDeploymentRestServiceImpl(engineName).getDeployment(deploymentId).deleteDeployment(deploymentId, uriInfo);

Here I am passing only single deployment Id but somehow it’s running into above error. Quite new to camunda so doesnt know what’s exactly it’s expecting.

Hi @abhinay_pandey,

in the process of deleting the deployments, the engine searches for the latest ProcessDefinition (corresponding to the deployment you are deleting). It seems like there are three ProcessDefinitions with the same version so the query returns all three, but only one was expected.

I saw that you raised another topic with a question similar to this issue. (Process Deployments have same version) I think they might be related. Did you make any progress here?

Cheers,
Miklas

@Miklas
Yes, because of same version, the query was returning more than one result. Even though this issue is resolved now I still have some doubts. Does it takes version into account while fetching the deployments? As I am passing a deploymentId so it should delete that particular deployment.

Hi @abhinay_pandey,

happy to hear that you could resolve everything.
The error does not occur because of multiples of the same deployment version. When you delete a deployment all ProcessDefinitions related to the deployment and all their ProcessInstances are deleted as well. The error occurred because the ProcessDefinition versions were the same.

Cheers,
Miklas

1 Like