{"record":{"id":"b9496ffe70409a67","repo":"flowable/flowable-engine","slug":"cannot-get-id-from-jpa-entity-no-id-method-field-b9496f","errorCode":null,"errorMessage":"Cannot get id from JPA Entity, no id method/field set","messagePattern":"Cannot get id from JPA Entity, no id method/field set","errorType":"exception","errorClass":"ActivitiException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/variable/JPAEntityMappings.java","lineNumber":109,"sourceCode":"\n    public Object getIdValue(Object value, EntityMetaData metaData) {\n        try {\n            if (metaData.getIdMethod() != null) {\n                return metaData.getIdMethod().invoke(value);\n            } else if (metaData.getIdField() != null) {\n                return metaData.getIdField().get(value);\n            }\n        } catch (IllegalArgumentException iae) {\n            throw new ActivitiException(\"Illegal argument exception when getting value from id method/field on JPAEntity\", iae);\n        } catch (IllegalAccessException iae) {\n            throw new ActivitiException(\"Cannot access id method/field for JPA Entity\", iae);\n        } catch (InvocationTargetException ite) {\n            throw new ActivitiException(\"Exception occurred while getting value from id field/method on JPAEntity: \" +\n                    ite.getCause().getMessage(), ite.getCause());\n        }\n\n        // Fall trough when no method and field is set\n        throw new ActivitiException(\"Cannot get id from JPA Entity, no id method/field set\");\n    }\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        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","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/variable/JPAEntityMappings.java#L91-L127","documentation":"Configuration failure in flowable5 JPAEntityMappings.getIdValue: the JPA entity's metadata has neither an id method nor an id field configured, so the primary key of the JPA entity used as a process variable cannot be extracted for serialization. The JPA variable mapping must declare the id method/field.","triggerScenarios":"Serializing/deserializing a JPA entity variable whose class has no @Id (or javax.persistence.Id) annotation, or whose id metadata was not detected by the entity scanner.","commonSituations":"Entities using only @EmbeddedId or a custom key class not recognized; forgot @Id entirely; id annotated with a non-standard annotation; entity scanner configuration missing the class.","solutions":["Add a standard @Id (javax.persistence.Id / jakarta.persistence.Id) annotation to a field or getter of the entity","If using a composite key, ensure the scanner/metadata recognizes the @EmbeddedId setup used by this engine version","Verify the flowable JPA configuration (jpaHandleTransaction/jpaEntityManagerFactory) points at the right persistence unit"],"exampleFix":"// before\n@Entity\npublic class Order { private Long id; }\n// after\n@Entity\npublic class Order { @Id private Long id; }","handlingStrategy":"validation","validationCode":"boolean hasId(Class<?> c) {\n    for (Field f : c.getDeclaredFields()) if (f.isAnnotationPresent(javax.persistence.Id.class)) return true;\n    for (Method m : c.getMethods()) if (m.isAnnotationPresent(javax.persistence.Id.class)) return true;\n    return false;\n}","typeGuard":null,"tryCatchPattern":"try {\n    runtimeService.setVariable(id, \"order\", entity);\n} catch (ActivitiException e) {\n    if (e.getMessage().contains(\"no id method/field set\")) {\n        throw new IllegalStateException(\"Entity \" + entity.getClass() + \" lacks @Id\", e);\n    } else { throw e; }\n}","preventionTips":["Always annotate exactly one @Id member per entity","Avoid relying on @EmbeddedId with this legacy mapping","Test JPA variable storage for each entity type at startup"],"tags":["jpa","missing-annotation","primary-key"],"backgroundTag":"missing-required-argument","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}