{"record":{"id":"3ebca9ebbfec8330","repo":"flowable/flowable-engine","slug":"cannot-get-id-from-jpa-entity-no-id-method-field","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":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/types/JPAEntityMappings.java","lineNumber":106,"sourceCode":"    }\n\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 FlowableException(\"Illegal argument exception when getting value from id method/field on JPAEntity\", iae);\n        } catch (IllegalAccessException iae) {\n            throw new FlowableException(\"Cannot access id method/field for JPA Entity\", iae);\n        } catch (InvocationTargetException ite) {\n            throw new FlowableException(\"Exception occurred while getting value from id field/method on JPAEntity: \" + ite.getCause().getMessage(), ite.getCause());\n        }\n\n        // Fall trough when no method and field is set\n        throw new FlowableException(\"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\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) {","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/types/JPAEntityMappings.java#L88-L124","documentation":"Flowable could not find any way to read the primary key of a JPA entity variable: neither a configured id method nor id field exists in the EntityMetaData for that entity class. After the reflective branches fall through, Flowable throws this FlowableException.","triggerScenarios":"getIdValue() is called with metaData.getIdMethod() == null and metaData.getIdField() == null — i.e. the entity class has no @Id-annotated method or field that Flowable's EntityMetaDataScanner could discover, or the entity class was never scanned.","commonSituations":"Entity missing the @Id annotation entirely; @Id placed on something the scanner does not pick up (e.g. property access mismatch, or id declared only in a superclass that is not scanned/registered); entity class not listed in the JPA entity scan at configuration time; typo in the entity class name in configuration.","solutions":["Add a @Id (javax.persistence/jakarta.persistence) annotation on the entity's id field or getter and rescan/redeploy.","Ensure the entity class (and superclasses holding the id) is registered with Flowable's JPA entity mappings in the process engine configuration.","Verify property vs field access consistency: JPA/Flowable must find the @Id on the access type actually used by the entity.","Rebuild EntityMetaData after changing the entity (Flowable scans classes at startup; stale metadata yields null id method/field)."],"exampleFix":"// before\npublic class Order { private Long id; } // no @Id\n// after\n@Entity\npublic class Order {\n    @Id\n    @GeneratedValue\n    private Long id;\n}","handlingStrategy":"validation","validationCode":"// fail fast at startup if an entity has no discoverable @Id\nfor (Class<?> c : entityClasses) {\n    boolean hasId = java.util.Arrays.stream(c.getDeclaredFields()).anyMatch(f -> f.isAnnotationPresent(javax.persistence.Id.class))\n        || java.util.Arrays.stream(c.getMethods()).anyMatch(m -> m.isAnnotationPresent(javax.persistence.Id.class));\n    if (!hasId) throw new IllegalStateException(c.getName() + \" has no @Id\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    Object v = runtimeService.getVariable(executionId, \"jpaVar\");\n} catch (org.flowable.common.engine.api.FlowableException e) {\n    if (e.getMessage().contains(\"no id method/field set\")) {\n        // fix entity mapping and redeploy\n    }\n}","preventionTips":["Annotate exactly one @Id field or getter per entity.","Register all entities (including superclasses carrying the id) in the engine's JPA configuration.","Keep JPA access type (field vs property) consistent across the entity hierarchy.","Run an entity-metadata scan test at build time."],"tags":["jpa","entity-mapping","missing-id","metadata"],"backgroundTag":"missing-required-config-field","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"}