{"record":{"id":"ba491bc7e6fd0e65","repo":"flowable/flowable-engine","slug":"entity-does-not-exist","errorCode":null,"errorMessage":"Entity does not exist:  - ","messagePattern":"Entity does not exist:  - ","errorType":"exception","errorClass":"ActivitiException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/variable/JPAEntityMappings.java","lineNumber":134,"sourceCode":"        EntityMetaData metaData = getEntityMetaData(entityClass);\n        if (metaData == null) {\n            throw new ActivitiIllegalArgumentException(\"Class is not a JPA-entity: \" + className);\n        }\n\n        // Create primary key of right type\n        Object primaryKey = createId(metaData, idString);\n        return findEntity(entityClass, primaryKey);\n    }\n\n    private Object findEntity(Class<?> entityClass, Object primaryKey) {\n        EntityManager em = Context\n                .getCommandContext()\n                .getSession(EntityManagerSession.class)\n                .getEntityManager();\n\n        Object entity = em.find(entityClass, primaryKey);\n        if (entity == null) {\n            throw new ActivitiException(\"Entity does not exist: \" + entityClass.getName() + \" - \" + primaryKey);\n        }\n        return entity;\n    }\n\n    public Object createId(EntityMetaData metaData, String string) {\n        Class<?> type = metaData.getIdType();\n        // According to JPA-spec all primitive types (and wrappers) are supported, String, util.Date, sql.Date,\n        // BigDecimal and BigInteger\n        if (type == Long.class || type == long.class) {\n            return Long.parseLong(string);\n        } else if (type == String.class) {\n            return string;\n        } else if (type == Byte.class || type == byte.class) {\n            return Byte.parseByte(string);\n        } else if (type == Short.class || type == short.class) {\n            return Short.parseShort(string);\n        } else if (type == Integer.class || type == int.class) {\n            return Integer.parseInt(string);","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/variable/JPAEntityMappings.java#L116-L152","documentation":"findEntity performs EntityManager.find(entityClass, primaryKey); if the persistence layer returns null, the engine throws this ActivitiException because the stored variable references an entity row that no longer exists.","triggerScenarios":"Reading a JPA entity process variable whose underlying database row was deleted between variable creation and lookup; wrong EntityManagerFactory/persistence unit configured so find runs against another database.","commonSituations":"Entity purged by a cleanup job while the process instance still references it; pointing the engine at a different datasource in another environment (test vs prod); entity deleted by a cascade or manual SQL.","solutions":["Recreate the missing row or complete/terminate the process instance referencing it","Verify the engine's EntityManagerFactory/datasource configuration matches the database holding the entity","Prevent deletion of entities still referenced by running process instances (FK/soft-delete)","Handle ActivitiException when reading variables that may reference deleted entities"],"exampleFix":"// before\nOrder order = (Order) runtimeService.getVariable(executionId, \"order\"); // throws if row deleted\n// after\nOrder row = em.find(Order.class, storedId);\nif (row != null) {\n    Order order = (Order) runtimeService.getVariable(executionId, \"order\");\n} else {\n    runtimeService.removeVariable(executionId, \"order\");\n}","handlingStrategy":"try-catch","validationCode":"Object exists = em.find(Order.class, storedId);\nif (exists == null) {\n    runtimeService.removeVariable(executionId, \"order\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    Order order = (Order) runtimeService.getVariable(executionId, \"order\");\n} catch (ActivitiException e) {\n    if (e.getMessage().startsWith(\"Entity does not exist\")) {\n        // row was deleted; recover or remove the variable\n        runtimeService.removeVariable(executionId, \"order\");\n    } else { throw e; }\n}","preventionTips":["Do not delete rows referenced by running process instances","Use soft deletes for entities used as process variables","Verify the engine's EntityManagerFactory datasource per environment"],"tags":["jpa","entity-not-found","database"],"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-14T11:17:12.474Z"}