{"record":{"id":"5cc698c394cdebee","repo":"flowable/flowable-engine","slug":"the-stage-plan-item-instance-id-could-not-be-foun","errorCode":null,"errorMessage":"The stage plan item instance id  could not be found or is no longer active.","messagePattern":"The stage plan item instance id  could not be found or is no longer active\\.","errorType":"exception","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/CreateInjectedPlanItemInstanceCmd.java","lineNumber":106,"sourceCode":"            .tenantId(tenantId)\n            .addToParent(true)\n            .create();\n\n        // after adding the plan item to the stage, add it to the agenda for creation and afterwards for activation processing\n        CmmnEngineAgenda agenda = CommandContextUtil.getAgenda(commandContext);\n        agenda.planCreatePlanItemInstanceOperation(planItemInstanceEntity);\n        agenda.planEvaluateToActivatePlanItemInstanceOperation(planItemInstanceEntity);\n\n        return planItemInstanceEntity;\n    }\n\n    protected PlanItemInstanceEntity getStageInstanceEntity(CommandContext commandContext) {\n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        PlanItemInstanceEntity planItemInstanceEntity = cmmnEngineConfiguration.getPlanItemInstanceEntityManager()\n            .findById(planItemInstanceBuilder.getStagePlanItemInstanceId());\n\n        if (planItemInstanceEntity == null) {\n            throw new FlowableIllegalArgumentException(\n                \"The stage plan item instance id \" + planItemInstanceBuilder.getStagePlanItemInstanceId() + \" could not be found or is no longer active.\");\n        }\n        if (!planItemInstanceEntity.isStage()) {\n            throw new FlowableIllegalArgumentException(\"A dynamically created plan item can only be injected into a running stage plan item.\");\n        }\n        return planItemInstanceEntity;\n    }\n\n    protected CaseInstanceEntity getCaseInstanceEntity(CommandContext commandContext) {\n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        CaseInstanceEntity caseInstanceEntity = cmmnEngineConfiguration.getCaseInstanceEntityManager().findById(planItemInstanceBuilder.getCaseInstanceId());\n        if (caseInstanceEntity == null) {\n            throw new FlowableIllegalArgumentException(\n                \"The case instance with id \" + planItemInstanceBuilder.getCaseInstanceId() + \" could not be found or is no longer an active case instance.\");\n        }\n        return caseInstanceEntity;\n    }\n}","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/CreateInjectedPlanItemInstanceCmd.java#L88-L124","documentation":"CreateInjectedPlanItemInstanceCmd looks up the target stage plan item instance by id before injecting a dynamically created plan item into it. When the PlanItemInstanceEntityManager returns null for the given stagePlanItemInstanceId, the command throws this FlowableIllegalArgumentException. It means the id does not exist, points to a different engine/database, or the plan item instance has been terminated/completed and removed from active query scope.","triggerScenarios":"Calling dynamic injection APIs (e.g. CmmnRuntimeService.createPlanItemInstanceBuilder(...).stagePlanItemInstanceId(id).inject() / CreateInjectedPlanItemInstanceBuilder) with a stagePlanItemInstanceId that is null, misspelled, already ended, or belongs to another case engine configuration.","commonSituations":"Stale ids held across long-running transactions after the stage completed; passing a plan item id from a different engine or cluster; copying an id from history instead of runtime; test data referencing a dropped in-memory H2 database.","solutions":["Fetch the current stage id via CmmnRuntimeService.createPlanItemInstanceQuery().planItemInstanceStateActive()... before injecting, and pass the fresh id","Verify the plan item instance still exists and is active (query the runtime tables ACT_CMMN_RU_PLAN_ITEM_INST) before calling the injection builder","Confirm you are connected to the same CmmnEngineConfiguration/database that owns the case instance","Check that you are not passing a historic plan item instance id instead of a runtime one"],"exampleFix":"// before\nplanItemInstanceBuilder.stagePlanItemInstanceId(storedStageId).inject();\n// after\nPlanItemInstance stage = cmmnRuntimeService.createPlanItemInstanceQuery()\n    .planItemInstanceId(storedStageId)\n    .planItemInstanceState(PlanItemInstanceState.ACTIVE)\n    .singleResult();\nif (stage != null) {\n    planItemInstanceBuilder.stagePlanItemInstanceId(stage.getId()).inject();\n}","handlingStrategy":"validation","validationCode":"PlanItemInstance stage = cmmnRuntimeService.createPlanItemInstanceQuery()\n    .planItemInstanceId(stagePlanItemInstanceId)\n    .planItemInstanceState(PlanItemInstanceState.ACTIVE)\n    .singleResult();\nif (stage == null) throw new IllegalStateException(\"stage plan item not active: \" + stagePlanItemInstanceId);","typeGuard":null,"tryCatchPattern":"try { builder.stagePlanItemInstanceId(id).inject(); }\ncatch (FlowableIllegalArgumentException e) { if (e.getMessage().contains(\"could not be found or is no longer active\")) { /* refresh id and retry once */ } else throw e; }","preventionTips":["Always resolve stage ids from a fresh runtime query, never long-lived caches","Filter queries on active state before injecting","Keep injection calls within the same transaction/scope that verified the stage"],"tags":["cmmn","plan-item","resource-not-found","dynamic-injection"],"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"}