Exception while fetching JPAEntity result variable

When ever I try to add JPAEntity and fetch as a result variable it throws exception. Why does the result variable fetch throws exception ? Please advise the same

Code Snippet

val processInstance: ProcessInstance = runTime.startProcessInstanceByKey(“Signup”, variable)
val executionEntity: ExecutionEntity = processInstance as ExecutionEntity

// check if newly creared object is availabe
if (executionEntity.getVariable(“contactInfo”) != null) {
return executionEntity.getVariable(“contactInfo”) as ContactInfo
}

// Returning method

fun addUser(execution: DelegateExecution): ContactInfo? {
if (!isEMailExist(execution.getVariable(“primaryEmail”) as String)) {
return saveContactInfo(execution.getVariables())
}

// Returning null if the user already exist.
execution.setVariable(“error”, CustomGraphQLException(2001, "PrimaryEmail already exist ", null))
return null
}

Process xml

<serviceTask id="servicetask2" name="AddUser" flowable:expression="#{contactinfodao.addUser(execution)}" flowable:resultVariable="contactInfo"></serviceTask>

Exception

java.lang.NullPointerException: null
at org.flowable.variable.service.impl.types.JPAEntityMappings.findEntity(JPAEntityMappings.java:121) ~[flowable-variable-service-6.4.2.jar:6.4.2]
at org.flowable.variable.service.impl.types.JPAEntityMappings.getJPAEntity(JPAEntityMappings.java:117) ~[flowable-variable-service-6.4.2.jar:6.4.2]
at org.flowable.variable.service.impl.types.JPAEntityVariableType.getValue(JPAEntityVariableType.java:84) ~[flowable-variable-service-6.4.2.jar:6.4.2]
at org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntityImpl.getValue(VariableInstanceEntityImpl.java:132) ~[flowable-variable-service-6.4.2.jar:6.4.2]
at org.flowable.variable.service.impl.persistence.entity.VariableScopeImpl.getVariable(VariableScopeImpl.java:271) ~[flowable-variable-service-6.4.2.jar:6.4.2]
at org.flowable.variable.service.impl.persistence.entity.VariableScopeImpl.getVariable(VariableScopeImpl.java:250) ~[flowable-variable-service-6.4.2.jar:6.4.2]
at com.resolver.signUpUser(CamMutation.kt:44) ~[main/:na]
at com.resolver.mutation.MutationMethodAccess.invoke(Unknown Source) ~[reflectasm-1.11.7.jar:na]

The problem is that there is no CommandContext and you are using internal classes (the cast to ExecutionEntity. After starting you should only look at the ProcessInstance and you should use ProcessInstance#getProcessVariables. Keep in mind that currently that will return an empty list, but we are working on a solution for that for the next release.

In the meantime you need to get the variable via the runtime service. RuntimeService#getVariable(String, String, Class). In your case it would look like:

Java code:

runtimeService.getVariable(processInstance.getId(), "contactInfo", ContactInfo.class)

Cheers,
Filip

@filiphr Thank you for the response.

 val test = runTime.getVariable(processInstance.getId(), "contactInfo", ContactInfo::class.java)

When I try to execute the above code I get the below Exception. I believe that the variable cannot be accessed after the task is completed. Please assist me on this.

Exception

org.flowable.common.engine.api.FlowableObjectNotFoundException: execution 5e2ae425-f3da-11e9-b0ab-d8d090041938 doesn’t exist
at org.flowable.engine.impl.cmd.GetExecutionVariableCmd.execute(GetExecutionVariableCmd.java:56) ~[flowable-engine-6.4.2.jar:6.4.2]
at org.flowable.engine.impl.interceptor.CommandInvoker$1.run(CommandInvoker.java:51) ~[flowable-engine-6.4.2.jar:6.4.2]
at org.flowable.engine.impl.interceptor.CommandInvoker.executeOperation(CommandInvoker.java:93) ~[flowable-engine-6.4.2.jar:6.4.2]
at org.flowable.engine.impl.interceptor.CommandInvoker.executeOperations(CommandInvoker.java:72) ~[flowable-engine-6.4.2.jar:6.4.2]
at org.flowable.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:56) ~[flowable-engine-6.4.2.jar:6.4.2]
at org.flowable.engine.impl.interceptor.BpmnOverrideContextInterceptor.execute(BpmnOverrideContextInterceptor.java:25) ~[flowable-engine-6.4.2.jar:6.4.2]
at org.flowable.common.engine.impl.interceptor.TransactionContextInterceptor.execute(TransactionContextInterceptor.java:53) ~[flowable-engine-common-6.4.2.jar:6.4.2]
at org.flowable.common.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:72) ~[flowable-engine-common-6.4.2.jar:6.4.2]
at org.flowable.common.spring.SpringTransactionInterceptor.lambda$execute$0(SpringTransactionInterceptor.java:56) ~[flowable-spring-common-6.4.2.jar:6.4.2]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.flowable.common.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:56) ~[flowable-spring-common-6.4.2.jar:6.4.2]
at org.flowable.common.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30) ~[flowable-engine-common-6.4.2.jar:6.4.2]
at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:56) ~[flowable-engine-common-6.4.2.jar:6.4.2]
at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:51) ~[flowable-engine-common-6.4.2.jar:6.4.2]
at org.flowable.engine.impl.RuntimeServiceImpl.getVariable(RuntimeServiceImpl.java:264) ~[flowable-engine-6.4.2.jar:6.4.2]
at org.flowable.engine.impl.RuntimeServiceImpl.getVariable(RuntimeServiceImpl.java:274) ~[flowable-engine-6.4.2.jar:6.4.2]
at com.resolver.mutation.MutationResolver.signUpUser(MutationResolver.kt:61) ~[main/:na]

Let me explain the scenario in detail. We have our own application RestAPI. Each rest request is mapped to a flowable process In each process we may have one or more task where each will return either a error object or application result object. Once the process is completed we want to fetch each and every result variable and return it in the response ( for the same request ). Can you advise how to fetch each and every task output after the task is completed. Please provide sample if possible also suggest if any best approach is available.

Thanks,
Raja

We know that the result variable can be fetched from HistorySevice. Is there any other way to fetch the result value for the sequence of java task? Please advise on the same.

As you’ve seen when the process is finished you can’t access the data via the RuntimeService and you should use the HistoryService.

Not sure how you are saving the variables for the java tasks, but if you are not saving them as local variables then they are on the process level. Looking at the XML you shared earlier you are using resultVariable on the service task. This would be stored on the process level. You can use the HistoryService to get those values.

Cheers,
Filip

1 Like