Link new Task to running process instance

Hello,

I’m using the process engine java api to create a new user task and link it to a running process instance.
bellow the code snippet used to do so:

 TaskEntity  newTask = (TaskEntity) taskService.newTask();        
    taskService.saveTask(newTask);
    newTask.setName("someTaskName");
    newTask.setTaskDefinitionKey("someTaskDefinitionKey");
    newTask.setCaseInstanceId(processInstance.getCaseInstanceId());
    newTask.setParentTaskId(executionEntity.getId())

The task is well created, linked to a parent task by it’s id and it’s case by the caseInstanceId

On the other hand, when trying to link it to the process instance, while debugging, i can see that those fileds are updated with correct vaules in my IDE, but when checking the database the (ProcessDefinitionId, ProcessInstanceId) in ACT_RU_TASK and ACT_HI_TASKINST are stored as nul values…

Bellow the code snippet i’m using to set the new created tasks process mapping fields:

    newTask.setProcessDefinitionId(processInstance.getProcessDefinitionId());       
    newTask.setProcessInstanceId(processInstance.getProcessInstanceId());
    newTask.setProcessInstance((ExecutionEntity) processInstance);
    taskService.saveTask(newTask);

Is their an explanation to this behavior please ?