我正在使用Jersey,并且正在将POST作为一个实体。但是,POST也将包含其以下关系之一的UUID

球衣资源:

@POST
public WorkstationEntity save (WorkstationEntity workstationEntity) {
            //WorkflowProcessEntity workflowProcessEntity = workflowProcessService.findByUUID();

    workstationService.save(workstationEntity);
    return workstationEntity;
}


如何调整以下映射,以便它可以识别关系并正确保存?当前workflow_process_id保存时为NULL,我必须手动查询该实体。

正在发布的JSON是... {name: Workstation 1; workflow_process_id: 1}

private WorkflowProcessEntity workflowProcess;

@ManyToOne
@JoinColumn(name = "workflow_process_id", referencedColumnName = "id")
public WorkflowProcessEntity getWorkflowProcess() {
    return workflowProcess;
}

public void setWorkflowProcess(WorkflowProcessEntity workflowProcess) {
    this.workflowProcess = workflowProcess;
}


workshopService

@Transactional
public void save(WorkstationEntity workstationEntity) {
    workstationRepository.save(workstationEntity);
}

最佳答案

您可以显示workstationService的代码吗?您使用的是Hibernatr还是简单的jdbc或任何其他orm tool

我认为在workstationService.save(workstationEntity);内部,您需要将workstationEntity附加到会话(如果是Hibernate Hibernate Session)。然后save它。

08-28 15:47