When using the JPA integration it is possible to use the entities as process variables e.g. in a multi-instance loop. The JPA provider may return a proxy object for the real entity e.g. for lazy loading in one-to-may collections.
Flowables way to get the Id of the entity object via reflection (at least for field access) for storing it as a process variable in JPAEntityMappings.getIdValue(Object value, EntityMetaData metaData) is broken when proxy objects are used. Tested with Hibernate 5.3.10 bundled with Spring Boot 2.1.5.
Tested with Flowable 6.4.1
Example Exception:
org.flowable.common.engine.api.FlowableIllegalArgumentException: Value of primary key for JPA-Entity cannot be null
at org.flowable.variable.service.impl.types.JPAEntityMappings.getIdString(JPAEntityMappings.java:168) ~[flowable-variable-service-6.4.1.jar:6.4.1]
at org.flowable.variable.service.impl.types.JPAEntityMappings.getJPAIdString(JPAEntityMappings.java:87) ~[flowable-variable-service-6.4.1.jar:6.4.1]
at org.flowable.variable.service.impl.types.JPAEntityVariableType.setValue(JPAEntityVariableType.java:72) ~[flowable-variable-service-6.4.1.jar:6.4.1]
at org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntityImpl.setValue(VariableInstanceEntityImpl.java:139) ~[flowable-variable-service-6.4.1.jar:6.4.1]
at org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntityManagerImpl.create(VariableInstanceEntityManagerImpl.java:50) ~[flowable-variable-service-6.4.1.jar:6.4.1]
at org.flowable.variable.service.impl.persistence.entity.VariableScopeImpl.createVariableInstance(VariableScopeImpl.java:887) ~[flowable-variable-service-6.4.1.jar:6.4.1]
at org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl.createVariableInstance(ExecutionEntityImpl.java:720) ~[flowable-engine-6.4.1.jar:6.4.1]
at org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl.createVariableLocal(ExecutionEntityImpl.java:741) ~[flowable-engine-6.4.1.jar:6.4.1]
at org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl.setVariableLocal(ExecutionEntityImpl.java:684) ~[flowable-engine-6.4.1.jar:6.4.1]
at org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl.setVariableLocal(ExecutionEntityImpl.java:664) ~[flowable-engine-6.4.1.jar:6.4.1]
at org.flowable.variable.service.impl.persistence.entity.VariableScopeImpl.setVariableLocal(VariableScopeImpl.java:737) ~[flowable-variable-service-6.4.1.jar:6.4.1]
at org.flowable.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior.setLoopVariable(MultiInstanceActivityBehavior.java:401) ~[flowable-engine-6.4.1.jar:6.4.1]
at org.flowable.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior.executeOriginalBehavior(MultiInstanceActivityBehavior.java:319) ~[flowable-engine-6.4.1.jar:6.4.1]
at org.flowable.engine.impl.bpmn.behavior.ParallelMultiInstanceBehavior.createInstances(ParallelMultiInstanceBehavior.java:86) ~[flowable-engine-6.4.1.jar:6.4.1]
at org.flowable.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior.execute(MultiInstanceActivityBehavior.java:115) ~[flowable-engine-6.4.1.jar:6.4.1]
It looks like the field was identified, but its value via reflection is null, although calling a getter for the id on the object will return the correct value.
JPA 2.0 introduced a generic API for getting the identifier of an entity object via:
entityManagerFactory.getPersistenceUnitUtil().getIdentifier(value)
Maybe this API should be used instead of reflection.
When using the JPA integration it is possible to use the entities as process variables e.g. in a multi-instance loop. The JPA provider may return a proxy object for the real entity e.g. for lazy loading in one-to-may collections.
Flowables way to get the Id of the entity object via reflection (at least for field access) for storing it as a process variable in
JPAEntityMappings.getIdValue(Object value, EntityMetaData metaData)
is broken when proxy objects are used. Tested with Hibernate 5.3.10 bundled with Spring Boot 2.1.5.Tested with Flowable 6.4.1
Example Exception:
It looks like the field was identified, but its value via reflection is null, although calling a getter for the id on the object will return the correct value.
JPA 2.0 introduced a generic API for getting the identifier of an entity object via:
entityManagerFactory.getPersistenceUnitUtil().getIdentifier(value)
Maybe this API should be used instead of reflection.