{"record":{"id":"b1ddf95d851dbe02","repo":"Activiti/Activiti","slug":"entity-does-not-exist-entityclass-getname","errorCode":null,"errorMessage":"Entity does not exist: ${entityClass.getName()} - ${primaryKey}","messagePattern":"Entity does not exist: (.+?) - (.+?)","errorType":"exception","errorClass":"ActivitiException","httpStatus":null,"severity":"error","filePath":"activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/variable/JPAEntityMappings.java","lineNumber":138,"sourceCode":"    }\n\n    public Object getJPAEntity(String className, String idString) {\n        Class<?> entityClass = null;\n        entityClass = ReflectUtil.loadClass(className);\n\n        EntityMetaData metaData = getEntityMetaData(entityClass);\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.getCommandContext().getSession(EntityManagerSession.class).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\n        // 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) {","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/Activiti/Activiti/blob/56435b1a97deeafdc09dd40074b056c89fba5a8a/activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/variable/JPAEntityMappings.java#L120-L156","documentation":"findEntity resolves a stored JPA variable back into a live entity by calling EntityManager.find(entityClass, primaryKey). If the persistence provider returns null — no row with that primary key exists — Activiti throws ActivitiException 'Entity does not exist: <class> - <pk>'. The variable references an entity that has been deleted or never existed in the database.","triggerScenarios":"Deserializing a JPA process variable whose stored primary key no longer matches any DB row, e.g. during process execution after the referenced row was deleted, or with a variable saved against a different database/environment than the one currently configured.","commonSituations":"Entity rows purged by cleanup jobs or cascading deletes while processes referencing them still run; pointing the engine at a different schema/test DB that lacks the row; restoring process data without restoring entity data.","solutions":["Recreate/restore the missing row with the stored primary key.","Fix referential hygiene: prevent deletion of entities referenced by running process variables (FK constraints or soft-delete).","Verify the persistence unit/datasource points at the same database the variable was created against."],"exampleFix":"// before\ncustomerRepository.delete(customer); // row referenced by running process\n// after\n// soft delete or verify no active process variables reference the entity first\nif (!hasActiveProcessReferences(customer.getId())) {\n    customerRepository.delete(customer);\n}","handlingStrategy":"try-catch","validationCode":"// before relying on the variable, check the row still exists\nObject pk = /* stored primary key */;\nObject entity = entityManager.find(Order.class, pk);\nif (entity == null) {\n    logger.warn(\"Order \" + pk + \" no longer exists; handle or fail the process step\");\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        logger.warn(\"Referenced entity deleted; compensating...\");\n        // take alternate path or restore the row\n    } else { throw e; }\n}","preventionTips":["Prevent deletion of entities referenced by running processes (FK constraints, soft-delete)","Keep engine datasource and persistence unit pointed at the same DB","Archive entity data together with process data"],"tags":["jpa","entity-not-found","primary-key","persistence"],"backgroundTag":"entity-not-found","analyzedSha":"56435b1a97deeafdc09dd40074b056c89fba5a8a","analyzedAt":"2026-09-09T21:00:06.703Z","contentChangedAt":"2026-09-09T21:00:06.703Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}