flowable/flowable-engine · error · ActivitiException
Cannot access id method/field for JPA Entity
Error message
Cannot access id method/field for JPA Entity
What it means
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.
Source
Thrown at modules/flowable5-engine/src/main/java/org/activiti/engine/impl/variable/JPAEntityMappings.java:102
EntityMetaData metaData = getEntityMetaData(value.getClass());
if (!metaData.isJPAEntity()) {
throw new ActivitiIllegalArgumentException("Object is not a JPA Entity: class='" + value.getClass() + "', " + value);
}
Object idValue = getIdValue(value, metaData);
return getIdString(idValue);
}
public Object getIdValue(Object value, EntityMetaData metaData) {
try {
if (metaData.getIdMethod() != null) {
return metaData.getIdMethod().invoke(value);
} else if (metaData.getIdField() != null) {
return metaData.getIdField().get(value);
}
} catch (IllegalArgumentException iae) {
throw new ActivitiException("Illegal argument exception when getting value from id method/field on JPAEntity", iae);
} catch (IllegalAccessException iae) {
throw new ActivitiException("Cannot access id method/field for JPA Entity", iae);
} catch (InvocationTargetException ite) {
throw new ActivitiException("Exception occurred while getting value from id field/method on JPAEntity: " +
ite.getCause().getMessage(), ite.getCause());
}
// Fall trough when no method and field is set
throw new ActivitiException("Cannot get id from JPA Entity, no id method/field set");
}
public Object getJPAEntity(String className, String idString) {
Class<?> entityClass = null;
entityClass = ReflectUtil.loadClass(className);
EntityMetaData metaData = getEntityMetaData(entityClass);
if (metaData == null) {
throw new ActivitiIllegalArgumentException("Class is not a JPA-entity: " + className);
}
View on GitHub (pinned to d6d39ce1c6)
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
Example fix
// before
@Entity
public class Order { @Id private Long id; }
// after
@Entity
public class Order {
@Id
private Long id;
public Long getId() { return id; }
} Defensive patterns
Strategy: try-catch
Validate before calling
Field id = entityClass.getDeclaredField("id");
if (!Modifier.isPublic(id.getModifiers()) && id.getGetter() == null) {
throw new IllegalStateException("@Id member must be accessible");
} Type guard
boolean isAccessibleId(Member m) {
return Modifier.isPublic(m.getModifiers());
} Try / catch
try {
Object id = mappings.getJPAIdString(entity);
} catch (ActivitiException e) {
if (e.getMessage().contains("Cannot access id method/field")) {
// add --add-opens or make the id member public
} else { throw e; }
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "You do not have permission" / 403 Forbidden errors: authenticated but not allowed — causes and fixes across open-source libraries — this error's family across 31 libraries.
Related errors
- Illegal access when calling '${name}' on class ${target.getC
- Illegal access when calling '<fieldName>' on class <classNam
- Illegal argument exception when getting value from id method
- Cannot access id method/field for JPA Entity
- Exception occurred while getting value from id field/method
AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11).
Data as JSON: /api/errors/bb95f792b1408d79.
Report an issue: GitHub.