flowable/flowable-engine · error · FlowableException

Cannot find the case to migrate, with id${caseInstanceId}

Error message

Cannot find the case to migrate, with id${caseInstanceId}

What it means

migrateCaseInstance looks up the live case instance by id before migrating. If no CaseInstanceEntity exists for the given id, this FlowableException is thrown (note: the message lacks a space before the id).

Source

Thrown at modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/migration/CaseInstanceMigrationManagerImpl.java:216

            if (!hasPlanItemDefinition(cmmnModel, planItemDefinitionId)) {
                validationResult.addValidationMessage("Invalid mapping for remove waiting for repetition plan item definition '" + planItemDefinitionId + "' cannot be found in the case definition");
            }
        }
        
        for (ChangePlanItemDefinitionWithNewTargetIdsMapping changePlanItemDefinitionIdMapping : document.getChangePlanItemDefinitionWithNewTargetIdsMappings()) {
            if (!hasPlanItemDefinition(cmmnModel, changePlanItemDefinitionIdMapping.getNewPlanItemDefinitionId())) {
                validationResult.addValidationMessage("Invalid mapping for changing the plan item definition id from '" + changePlanItemDefinitionIdMapping.getExistingPlanItemDefinitionId() + 
                        "' to '" + changePlanItemDefinitionIdMapping.getNewPlanItemDefinitionId() + "', because the target can not be found in the case definition");
            }
        }
    }

    @Override
    public void migrateCaseInstance(String caseInstanceId, CaseInstanceMigrationDocument document, CommandContext commandContext) {
        CaseInstanceEntityManager caseInstanceEntityManager = CommandContextUtil.getCaseInstanceEntityManager(commandContext);
        CaseInstanceEntity caseInstance = caseInstanceEntityManager.findById(caseInstanceId);
        if (caseInstance == null) {
            throw new FlowableException("Cannot find the case to migrate, with id" + caseInstanceId);
        }

        CaseDefinition caseDefinitionToMigrateTo = resolveCaseDefinition(document, commandContext);
        doMigrateCaseInstance(caseInstance, caseDefinitionToMigrateTo, document, commandContext);
    }
    
    @Override
    public void migrateHistoricCaseInstance(String caseInstanceId, HistoricCaseInstanceMigrationDocument document, CommandContext commandContext) {
        HistoricCaseInstanceEntityManager historicCaseInstanceEntityManager = CommandContextUtil.getHistoricCaseInstanceEntityManager(commandContext);
        HistoricCaseInstanceEntity caseInstance = historicCaseInstanceEntityManager.findById(caseInstanceId);
        if (caseInstance == null) {
            throw new FlowableException("Cannot find the historic case instance to migrate, with id" + caseInstanceId);
        }
        
        if (!CaseInstanceState.END_STATES.contains(caseInstance.getState())) {
            throw new FlowableException("Historic case instance has not ended and can only be migrated with the regular case instance migrate method (migrateCaseInstance) for id " + caseInstanceId);
        }

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Query CaseService.createCaseInstanceQuery().caseInstanceId(id) first to confirm the instance exists and is running
  2. Use the correct id (from case instance query results) and correct engine/datasource
  3. If the case already ended, use migrateHistoricCaseInstance instead
  4. Fix the missing-space message if you control a fork: 'with id ' + caseInstanceId

Example fix

// before
migrationManager.migrateCaseInstance(caseId, document, commandContext); // caseId may not exist
// after
if (caseService.createCaseInstanceQuery().caseInstanceId(caseId).count() > 0) {
    migrationManager.migrateCaseInstance(caseId, document, commandContext);
}
Defensive patterns

Strategy: validation

Validate before calling

const exists = caseService.createCaseInstanceQuery().caseInstanceId(caseId).count();
if (exists === 0) throw new Error('No running case instance with id ' + caseId);

Type guard

function isRunnableCase(q) { return q.singleResult() != null && !['completed','terminated','closed'].includes(q.singleResult().state); }

Try / catch

try { migrateCaseInstance(id, doc); } catch (e) { if (String(e.message).startsWith('Cannot find the case to migrate')) { throw new NotFoundError('Case instance ' + id + ' does not exist or already ended'); } throw e; }

Prevention

When it happens

Trigger: Calling CaseInstanceMigrationManager.migrateCaseInstance(caseInstanceId, document, commandContext) with an id that matches no running case instance (already ended, wrong engine/tenant, typo, or historic-only instance).

Common situations: Trying to migrate a completed case (must use historic migration); id taken from a different database/engine; case deleted before migration; using definition key instead of instance id by mistake.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11). Data as JSON: /api/errors/e12b94efc26af312. Report an issue: GitHub.