AnsweredAssumed Answered

Activiti rejects transient JPA object as process variable ?

Question asked by petercahyadi on Apr 1, 2012
Latest reply on Dec 12, 2014 by wdavilaneto
Hi,

I'm experiencing an issue when trying to pass a transient JPA object as an input parameter to a java service task, which then would persist the object.

my process definition looks like this :

   <process id="saveUom">
      <startEvent id="TheStartEvent" />
      <sequenceFlow id="Flow1" sourceRef="TheStartEvent" targetRef="uomService" />
      <serviceTask id="uomService" activiti:expression="#{uomService.createUom(input)}" />
      <sequenceFlow id="Flow2" sourceRef="uomService" targetRef="TheEndEvent" />
      <endEvent id="TheEndEvent" />
   </process>

Here the 'input' variable is a JPA transient object, that i'm trying to make persistent using the 'uomService'.
But when i trigger this process, i'm getting the below exception
org.activiti.engine.ActivitiException: Value of primary key for JPA-Entity cannot be null

the stack trace is as below

org.activiti.engine.impl.variable.JPAEntityMappings.getIdString(JPAEntityMappings.java:170)
org.activiti.engine.impl.variable.JPAEntityMappings.getJPAIdString(JPAEntityMappings.java:85)
org.activiti.engine.impl.variable.JPAEntityVariableType.setValue(JPAEntityVariableType.java:66)
org.activiti.engine.impl.persistence.entity.VariableInstanceEntity.setValue(VariableInstanceEntity.java:164)
org.activiti.engine.impl.persistence.entity.VariableInstanceEntity.create(VariableInstanceEntity.java:72)
org.activiti.engine.impl.persistence.entity.VariableInstanceEntity.createAndInsert(VariableInstanceEntity.java:58)
org.activiti.engine.impl.persistence.entity.VariableScopeImpl.createVariableLocal(VariableScopeImpl.java:225)
org.activiti.engine.impl.persistence.entity.VariableScopeImpl.setVariable(VariableScopeImpl.java:175)
org.activiti.engine.impl.persistence.entity.VariableScopeImpl.setVariables(VariableScopeImpl.java:264)
org.activiti.engine.impl.cmd.StartProcessInstanceCmd.execute(StartProcessInstanceCmd.java:69)
org.activiti.engine.impl.cmd.StartProcessInstanceCmd.execute(StartProcessInstanceCmd.java:31)
org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:42)
org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42)
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40)
org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
org.activiti.engine.impl.RuntimeServiceImpl.startProcessInstanceByKey(RuntimeServiceImpl.java:54)

What i understand so far from looking the JPAEntityMappings code, is that Activiti requires the process variable of JPA type (the class is annotated with @Entity) to have an Id of non null value. which in my case it would not be there, as the object is a transient object which i'm just about to persist.

Anybody can help to explain what's the reason for this ? because i think my scenario is  not an uncommon thing right ?

Thanks,

Peter.

Outcomes