{"record":{"id":"e2541aa1de08c301","repo":"flowable/flowable-engine","slug":"illegal-argument-exception-when-getting-value-from-e2541a","errorCode":null,"errorMessage":"Illegal argument exception when getting value from id method/field on JPAEntity","messagePattern":"Illegal argument exception when getting value from id method/field on JPAEntity","errorType":"exception","errorClass":"ActivitiException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/variable/JPAEntityMappings.java","lineNumber":100,"sourceCode":"\n    public String getJPAIdString(Object value) {\n        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);","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/variable/JPAEntityMappings.java#L82-L118","documentation":"getIdValue reads the entity's primary key by reflectively invoking the @Id-annotated getter or accessing the @Id field. If the reflective call throws IllegalArgumentException (e.g. wrong receiver object for the Method/Field), it is wrapped in this ActivitiException.","triggerScenarios":"Invoking getIdValue with a value object that is not an instance of the class the id Method/Field belongs to — typically a classloader mismatch (same class name loaded by two loaders) or a mismatched EntityMetaData cache entry.","commonSituations":"Hot redeployment in an app server leaving stale EntityMetaData pointing at an old classloader's Method/Field; passing a proxy that is not an instance of the entity class.","solutions":["Redeploy cleanly so cached EntityMetaData matches the current classloader","Ensure the object passed is an instance of the exact entity class the metadata was built from","Check for duplicate entity classes on the classpath (two jars with the same FQCN)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!metaClass.isInstance(value)) {\n    throw new IllegalArgumentException(\"value is not an instance of \" + metaClass.getName());\n}","typeGuard":"boolean matchesMetadata(Class<?> metaClass, Object v) {\n    return v != null && metaClass.isInstance(v);\n}","tryCatchPattern":"try {\n    Object id = mappings.getJPAIdString(entity);\n} catch (ActivitiException e) {\n    if (e.getMessage().contains(\"Illegal argument exception when getting value from id\")) {\n        // classloader/metadata mismatch — redeploy or rebuild metadata\n    } else { throw e; }\n}","preventionTips":["Redeploy cleanly after changing entity classes","Avoid duplicate entity classes on the classpath","Keep one classloader per engine configuration"],"tags":["jpa","reflection","classloader"],"backgroundTag":"internal-invariant-violation","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"}