{"record":{"id":"401056da31c493fe","repo":"flowable/flowable-engine","slug":"batch-entity-not-found-for-id-401056","errorCode":null,"errorMessage":"batch entity not found for id ","messagePattern":"batch entity not found for id ","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteBatchCmd.java","lineNumber":37,"sourceCode":"import org.flowable.common.engine.impl.interceptor.CommandContext;\nimport org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;\nimport org.flowable.engine.impl.util.CommandContextUtil;\n\npublic class DeleteBatchCmd implements Command<Void> {\n    \n    protected String batchId;\n    \n    public DeleteBatchCmd(String batchId) {\n        this.batchId = batchId;\n    }\n    \n    @Override\n    public Void execute(CommandContext commandContext) {\n        ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);\n        BatchService batchService = processEngineConfiguration.getBatchServiceConfiguration().getBatchService();\n        Batch batch = batchService.getBatch(batchId);\n        if (batch == null) {\n            throw new FlowableException(\"batch entity not found for id \" + batchId);\n        }\n        \n        batchService.deleteBatch(batchId);\n        \n        return null;\n    }\n}\n","sourceCodeStart":19,"sourceCodeEnd":45,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteBatchCmd.java#L19-L45","documentation":"DeleteBatchCmd loads the batch entity via the BatchService; if no batch exists for the given batchId it throws a plain FlowableException. Batches (e.g. async migration/delete jobs) must exist before they can be deleted.","triggerScenarios":"Calling ManagementService.deleteBatch(batchId) with an id that has no ACT_RU_BATCH row — already deleted, wrong id, or id from a different engine configuration/database.","commonSituations":"Double deletion of the same batch in retry logic; batch expired and was purged automatically; referencing a batch id captured before a database reset.","solutions":["Check existence first: processEngineConfiguration.getBatchServiceConfiguration().getBatchService().getBatch(batchId) (or keep your own registry) before deleting.","Treat deletion as idempotent: catch the FlowableException and skip if the batch is already gone.","Verify you are connected to the same database where the batch was created."],"exampleFix":"// before\nmanagementService.deleteBatch(batchId);\n// after\nBatch batch = ... getBatch(batchId);\nif (batch != null) {\n    managementService.deleteBatch(batchId);\n}","handlingStrategy":"try-catch","validationCode":"// Batch lookup requires engine internals; check your own registry or query managementService tables before deleting","typeGuard":null,"tryCatchPattern":"try {\n    managementService.deleteBatch(batchId);\n} catch (FlowableException e) {\n    if (e.getMessage().startsWith(\"batch entity not found\")) { log.info(\"Batch {} already gone\", batchId); } else { throw e; }\n}","preventionTips":["Make batch deletion idempotent in retry/dedup logic","Track created batch ids and mark them deleted in your own store","Confirm engine/database affinity before deleting batches"],"tags":["flowable","batch","delete"],"backgroundTag":"entity-not-found","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}