{"record":{"id":"323d78a1fc19c72a","repo":"flowable/flowable-engine","slug":"no-case-instance-found-for-id-caseinstanceentity","errorCode":null,"errorMessage":"No case instance found for id ${caseInstanceEntityId}","messagePattern":"No case instance found for id (.+?)","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/agenda/operation/TerminateCaseInstanceOperation.java","lineNumber":151,"sourceCode":"        return \"cmmn-state-transition-terminate-case\";\n    }\n\n    @Override\n    public void addAdditionalCallbackData(CallbackData callbackData) {\n        if (callbackData.getAdditionalData() == null) {\n            callbackData.setAdditionalData(new HashMap<>());\n        }\n        callbackData.getAdditionalData().put(CallbackConstants.EXIT_TYPE, exitType);\n        callbackData.getAdditionalData().put(CallbackConstants.EXIT_EVENT_TYPE, exitEventType);\n        callbackData.getAdditionalData().put(CallbackConstants.MANUAL_TERMINATION, manualTermination);\n    }\n\n    @Override\n    public CaseInstanceEntity getCaseInstanceEntity() {\n        if (caseInstanceEntity == null) {\n            caseInstanceEntity = CommandContextUtil.getCaseInstanceEntityManager(commandContext).findById(caseInstanceEntityId);\n            if (caseInstanceEntity == null) {\n                throw new FlowableObjectNotFoundException(\"No case instance found for id \" + caseInstanceEntityId);\n            }\n        }\n        return caseInstanceEntity;\n    }\n\n    public boolean isManualTermination() {\n        return manualTermination;\n    }\n\n    public void setManualTermination(boolean manualTermination) {\n        this.manualTermination = manualTermination;\n    }\n\n    public String getExitCriterionId() {\n        return exitCriterionId;\n    }\n\n    public void setExitCriterionId(String exitCriterionId) {","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/agenda/operation/TerminateCaseInstanceOperation.java#L133-L169","documentation":"TerminateCaseInstanceOperation.getCaseInstanceEntity lazily loads the case instance row via the CaseInstanceEntityManager. If no row exists for the stored id, the operation cannot proceed and throws FlowableObjectNotFoundException.","triggerScenarios":"Agenda operation created/referenced with a caseInstanceEntityId that no longer exists in ACT_CMMN_RU_CASE_INST — e.g. the case was already terminated/removed, or a wrong id was used to construct the operation/trigger the terminate command.","commonSituations":"Double termination racing so the second one finds no row; terminating with a stale case instance id from history (historic id reuse); database cleanup deleted runtime data.","solutions":["Verify the case instance id with CmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(id).count() before terminating.","Treat the termination as already done if the instance no longer exists; catch FlowableObjectNotFoundException as a no-op.","Check for concurrent terminate calls and serialize them.","Ensure you are not passing a historic case instance id to a runtime API."],"exampleFix":"// before\ncmmnRuntimeService.terminateCaseInstance(caseInstanceId);\n// after\nif (cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(caseInstanceId).count() > 0) {\n    cmmnRuntimeService.terminateCaseInstance(caseInstanceId);\n}","handlingStrategy":"validation","validationCode":"// java\nlong exists = cmmnRuntimeService.createCaseInstanceQuery()\n    .caseInstanceId(caseInstanceId).count();\nif (exists == 0) return; // already gone; skip terminate","typeGuard":null,"tryCatchPattern":"try {\n    cmmnRuntimeService.terminateCaseInstance(caseInstanceId);\n} catch (FlowableObjectNotFoundException e) {\n    // instance already terminated/removed: treat as success\n}","preventionTips":["Resolve case instance ids from runtime queries, never from stale caches.","Guard terminate operations against concurrent duplicate calls.","Distinguish runtime vs historic ids."],"tags":["cmmn","case-instance","not-found"],"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-14T05:17:10.506Z"}