cancel
Showing results for 
Search instead for 
Did you mean: 

BusinessKey is null for Executions

vicziani
Champ in-the-making
Champ in-the-making
I have a workflow with two User Task after a Parallel Gateway. I start the process with a BusinessKey. After that I have three executions. The BusinessKey of the execution of the parallel gateway is ok, but the BusinessKeys of the two User Tasks are null.

Is it normal?
4 REPLIES 4

frederikherema1
Star Contributor
Star Contributor
What about the "getProcessBusinessKey()" on the DelegateExecution? This should return the business-key set at the beginning not the process… The getBusinessKey() will only work if the execution you're using is the process-instance itself.


/** The business key for this execution. Only returns a value if the delegate execution
   * is a process instance.
   * 
   * @deprecated use {@link #getProcessBusinessKey()} to get the business key for the process
   *             associated with this execution, regardless whether or not this execution is a
   *             process-instance.
   */
  String getBusinessKey();

vicziani
Champ in-the-making
Champ in-the-making
getProcessBusinessKey throws NullPointerException.

java.lang.NullPointerException
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.ensureProcessInstanceInitialized(ExecutionEntity.java:669)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.getProcessInstance(ExecutionEntity.java:663)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.getProcessBusinessKey(ExecutionEntity.java:624)

And I cannot query the other executions with createExecutionQuery().processInstanceBusinessKey(), because their business key is null. I think the executions after the parallelgateway should be equals the businesskey of the parallelgateway.

What about the "getProcessBusinessKey()" on the DelegateExecution? This should return the business-key set at the beginning not the process… The getBusinessKey() will only work if the execution you're using is the process-instance itself.


/** The business key for this execution. Only returns a value if the delegate execution
   * is a process instance.
   * 
   * @deprecated use {@link #getProcessBusinessKey()} to get the business key for the process
   *             associated with this execution, regardless whether or not this execution is a
   *             process-instance.
   */
  String getBusinessKey();

frederikherema1
Star Contributor
Star Contributor
The null pointer is due to the fact you're nog using the execution inside activiti context (e.g.. JavaDelegate, listener) but rater just use the pogo that comes out of a query.

The query-method you are referring to only selects process-instances which have the given business key set. Since a business-key is a unique identifier for a single process-instance (also enforced on db-level), it doesn't make sense setting the BUSINESS_KEY_ field on the child executions as well (defeats the purpose).

If you want all child-executions of the process-instances with a given business-key, use this approach:


ProcessInstance pi  = runtime.createProcessInstanceQuery().processInstanceBusinessKey("myKey").singleResult();
List<Execution> executions = runtime.createExecutionQuery().processInstanceId(pi.getId().list();

vicziani
Champ in-the-making
Champ in-the-making
Thank you very much, understood, this works for me! Smiley Happy