Creating Native queries

Using the following native query as an example …

			.sql("Select HST.PROC_INST_ID_, HST.START_TIME_, HST.BUSINESS_KEY_  from "
					+  managementService.getTableName(HistoricProcessInstance.class) + " HST, "
					+  managementService.getTableName(HistoricVariableInstanceEntity.class) + " VAR "
					+ "WHERE VAR.PROC_INST_ID_ = HST.PROC_INST_ID_ "
					+ " AND HST.PROC_INST_ID_ = 'c72a6611-8431-11ea-80a1-0a580aab0d90' "
					+ "AND VAR.NAME_ = 'MOW_Status'"  + " and BUSINESS_KEY_ = 'MOWResearchRefunds'" )
			 .list(););

I was hoping only those fields that are in the SELECT statement (HST.PROC_INST_ID_, HST.START_TIME_, HST.BUSINESS_KEY_ ) would be returned in the LIST. However all fields are returned with values for only those in the select statement.

Is there a way to specifically return only those fields that are in the Select statement

Not sure I understand the purpose of originalPersistentState array and “persistentState” array being returned

What was returned

[
{
“id”: null,
“revision”: 1,
“originalPersistentState”: {
“processDefinitionId”: null,
“durationInMillis”: null,
“referenceType”: null,
“processDefinitionName”: null,
“endActivityId”: null,
“deleteReason”: null,
“referenceId”: null,
“processDefinitionKey”: null,
“callbackId”: null,
“deploymentId”: null,
“businessKey”: “MOWResearchRefunds”,
“name”: null,
“startTime”: “2020-04-22T00:39:51.793+0000”,
“endTime”: null,
“processDefinitionVersion”: null,
“superProcessInstanceId”: null,
“callbackType”: null
},
“processInstanceId”: “c72a6611-8431-11ea-80a1-0a580aab0d90”,
“processDefinitionId”: null,
“startTime”: “2020-04-22T00:39:51.793+0000”,
“endTime”: null,
“durationInMillis”: null,
“deleteReason”: null,
“endActivityId”: null,
“businessKey”: “MOWResearchRefunds”,
“startUserId”: null,
“startActivityId”: null,
“superProcessInstanceId”: null,
“tenantId”: “”,
“name”: null,
“localizedName”: null,
“description”: null,
“localizedDescription”: null,
“processDefinitionKey”: null,
“processDefinitionName”: null,
“processDefinitionVersion”: null,
“deploymentId”: null,
“callbackId”: null,
“callbackType”: null,
“referenceId”: null,
“referenceType”: null,
“queryVariables”: null,
“persistentState”: {
“processDefinitionId”: null,
“durationInMillis”: null,
“referenceType”: null,
“processDefinitionName”: null,
“endActivityId”: null,
“deleteReason”: null,
“referenceId”: null,
“processDefinitionKey”: null,
“callbackId”: null,
“deploymentId”: null,
“businessKey”: “MOWResearchRefunds”,
“name”: null,
“startTime”: “2020-04-22T00:39:51.793+0000”,
“endTime”: null,
“processDefinitionVersion”: null,
“superProcessInstanceId”: null,
“callbackType”: null
},
“processVariables”: {},
“idPrefix”: “PRC-”,
“inserted”: false,
“updated”: false,
“deleted”: false,
“revisionNext”: 2
}
]

That’s correct, the fields won’t be fetched and this is why they’re all null. If you’d do * instead, the relevant fields will be filled with a value.