Query return 3 results instead of max 1

In my example I’m using “HistoricVariableInstanceQuery” to get variables from history for last user task as in case of last user task process exexcution ends and so instead of RuntimeService I’m using HistoricVariableInstanceQuery as below

final TypedValue characteristicValue = historyVariableInstanceQuery .variableName(TaskConstants.CHARACTERISTIC).singleResult().getTypedValue();

where Characteristic is object which I passed to execute the user task, but is giving error as mentioned in the title.


In the given Bpm I have mark the user task which is giving error.

Hey @sunnyorange,

Your query has more than one result. With the singleResult() method you are expecting one or no result. Refer to the JavaDoc of the method:

   * Executes the query and returns the resulting entity or null if no
   * entity matches the query criteria.
   * @throws ProcessEngineException when the query results in more than one
   * entities.
  U singleResult();

Use the list()method instead:

List<HistoricVariableInstance> instances = historyVariableInstanceQuery.variableName(TaskConstants.CHARACTERISTIC).list();

Hope this helps you!