flowable/flowable-engine · error · FlowableException
Exception occurred while getting value from id field/method
Error message
Exception occurred while getting value from id field/method on JPAEntity: ${cause} What it means
Reading a JPA entity variable's id reflectively caused the invoked getter method (or field accessor path) to itself throw; reflection wraps that in InvocationTargetException. Flowable unwraps it and rethrows the underlying cause inside a FlowableException whose message includes the cause's message.
Source
Thrown at modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/types/JPAEntityMappings.java:102
throw new FlowableIllegalArgumentException("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 FlowableException("Illegal argument exception when getting value from id method/field on JPAEntity", iae);
} catch (IllegalAccessException iae) {
throw new FlowableException("Cannot access id method/field for JPA Entity", iae);
} catch (InvocationTargetException ite) {
throw new FlowableException("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 FlowableException("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);
// Create primary key of right type
Object primaryKey = createId(metaData, idString);
return findEntity(entityClass, primaryKey);
}
private Object findEntity(Class<?> entityClass, Object primaryKey) {View on GitHub (pinned to d6d39ce1c6)
Solutions
- Read the exception cause (ite.getCause()) — fix the real failure inside the entity's id getter, not the Flowable wrapper.
- Use field-based @Id access (no getter logic) or a plain getter that just returns the field without lazy logic.
- Ensure the EntityManager/session is still open when the variable value is accessed (JPA entity variable types configured with proper session handling, e.g. jpaHandleTransaction=true).
- Initialize the id before the entity becomes detached (id assigned at persist time, e.g. with @GeneratedValue and a flush).
Example fix
// before
@Id
@GeneratedValue
private Long id;
public Long getId() { return session.load(...).getId(); } // throws when detached
// after
@Id
@GeneratedValue
private Long id;
public Long getId() { return this.id; } // plain field access Defensive patterns
Strategy: try-catch
Validate before calling
// check the getter does not depend on an open session before detaching
if (entityManager.contains(entity)) { /* still managed, safe to read id */ } Try / catch
try {
Object v = taskService.getVariable(taskId, "jpaVar");
} catch (org.flowable.common.engine.api.FlowableException e) {
Throwable cause = e.getCause();
if (cause instanceof org.hibernate.LazyInitializationException) {
// reopen session / reattach entity and retry
}
} Prevention
- Keep id getters trivial (return the field, no lazy logic).
- Use field-based @Id access to avoid executing getter code.
- Flush after persist so the id is assigned before the entity is stored as a variable.
- Keep the EntityManager session open during variable access (jpaHandleTransaction=true).
When it happens
Trigger: getIdValue() invokes metaData.getIdMethod().invoke(value) and the entity's @Id getter throws any RuntimeException/Error (e.g. lazy-initialization LazyInitializationException, NullPointerException inside the getter, database access from getter).
Common situations: Accessing an uninitialized lazy proxy/attribute outside a Hibernate session when Flowable reads the id to serialize the variable; getter with custom logic that depends on session or transient state; entity modified to add logic in the getter that fails for detached instances.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Exception while invoking '${name}' on class ${target.getClas
- Illegal argument exception when getting value from id method
- Cannot access id method/field for JPA Entity
- Illegal argument exception when getting value from id method
- Cannot access id method/field for JPA Entity
AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11).
Data as JSON: /api/errors/1d51f4a21aae1130.
Report an issue: GitHub.