{"record":{"id":"8148adf307f965be","repo":"flowable/flowable-engine","slug":"batch-entity-not-found-for-id","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-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/DeleteBatchCmd.java","lineNumber":37,"sourceCode":"import org.flowable.common.engine.api.FlowableException;\nimport org.flowable.common.engine.impl.interceptor.Command;\nimport org.flowable.common.engine.impl.interceptor.CommandContext;\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        CmmnEngineConfiguration engineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        BatchService batchService = engineConfiguration.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-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/DeleteBatchCmd.java#L19-L45","documentation":"DeleteBatchCmd delegates to the BatchService to load the batch entity for the given batchId; if the service returns null, the command throws a plain FlowableException. Batches (e.g. for bulk deletions/migrations) may already have been deleted, cleaned up by the async history/job executor, or the id may be wrong.","triggerScenarios":"Calling CmmnManagementService.deleteBatch(batchId) (or the deleteBatchCmd) with an id that never existed, was already deleted, or whose batch rows were purged.","commonSituations":"Double-invocation of a delete routine; referencing a batch id from a different engine/database; retention/cleanup jobs removing the batch before the explicit delete runs.","solutions":["Check batch existence first via batchService/query APIs (e.g. managementService.findBatch(...) or batch query) and skip deletion when absent","Ensure the delete is idempotent: catch FlowableException with this message and treat it as success","Verify the batchId comes from the same engine configuration/database"],"exampleFix":"// before\nmanagementService.deleteBatch(batchId);\n// after\nBatch batch = managementService.findBatch(batchId);\nif (batch != null) {\n    managementService.deleteBatch(batchId);\n}","handlingStrategy":"try-catch","validationCode":"Batch batch = managementService.findBatch(batchId);\nboolean exists = batch != null;","typeGuard":null,"tryCatchPattern":"try { managementService.deleteBatch(batchId); }\ncatch (FlowableException e) { if (e.getMessage() != null && e.getMessage().startsWith(\"batch entity not found\")) { log.info(\"batch already gone: {}\", batchId); } else throw e; }","preventionTips":["Make batch deletion idempotent — treat not-found as success","Avoid double-invoking delete from retry logic","Source batch ids from the same engine instance that created them"],"tags":["cmmn","batch","resource-not-found","idempotency"],"backgroundTag":"record-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"}