{"record":{"id":"bb95f792b1408d79","repo":"flowable/flowable-engine","slug":"cannot-access-id-method-field-for-jpa-entity-bb95f7","errorCode":null,"errorMessage":"Cannot access id method/field for JPA Entity","messagePattern":"Cannot access id method/field for JPA Entity","errorType":"exception","errorClass":"ActivitiException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/variable/JPAEntityMappings.java","lineNumber":102,"sourceCode":"        EntityMetaData metaData = getEntityMetaData(value.getClass());\n        if (!metaData.isJPAEntity()) {\n            throw new ActivitiIllegalArgumentException(\"Object is not a JPA Entity: class='\" + value.getClass() + \"', \" + value);\n        }\n        Object idValue = getIdValue(value, metaData);\n        return getIdString(idValue);\n    }\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 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","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/variable/JPAEntityMappings.java#L84-L120","documentation":"Reflective access to the JPA entity's id member failed (IllegalAccessException/IllegalArgumentException path) while reading the id value in JPAEntityMappings.getIdValue; the id method/field is not accessible.","triggerScenarios":"An @Id field or getter that is private/protected and, on JDK 9+, not opened to the engine module (setAccessible fails or is not applied), so Field.get / Method.invoke is denied.","commonSituations":"Java 16+ strong encapsulation blocking reflection into another module or JDK package; entity in a sealed jar with security manager restrictions; JPAResourceIdField/JPAResourceIdMethod metadata pointing at a non-public member without access being set.","solutions":["Make the @Id field/getter public, or ensure it has a public getter","On JPMS, add module declarations opening the entity package (opens com.example.entity; to the engine module)","Add --add-opens JVM flags for the blocked package","Prefer the @Id accessor method over a private field"],"exampleFix":"// before\n@Entity\npublic class Order { @Id private Long id; }\n// after\n@Entity\npublic class Order {\n    @Id\n    private Long id;\n    public Long getId() { return id; }\n}","handlingStrategy":"try-catch","validationCode":"Field id = entityClass.getDeclaredField(\"id\");\nif (!Modifier.isPublic(id.getModifiers()) && id.getGetter() == null) {\n    throw new IllegalStateException(\"@Id member must be accessible\");\n}","typeGuard":"boolean isAccessibleId(Member m) {\n    return Modifier.isPublic(m.getModifiers());\n}","tryCatchPattern":"try {\n    Object id = mappings.getJPAIdString(entity);\n} catch (ActivitiException e) {\n    if (e.getMessage().contains(\"Cannot access id method/field\")) {\n        // add --add-opens or make the id member public\n    } else { throw e; }\n}","preventionTips":["Make @Id fields public or expose a public getter","On JPMS, open entity packages to the engine module","On JDK 16+, verify reflection with --add-opens flags"],"tags":["jpa","reflection","access-modifier","java-9"],"backgroundTag":"insufficient-permissions","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}