Я делаю однонаправленное отображение один на один.
ActivitiProcessDeployment class
@Entity
@Table(name="act_re_deployment")
public class ActivitiProcessDeployment implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@JsonIgnore
@Id
@JsonProperty
@Column(name="id_")
private String id;
@JsonProperty
@Column(name="name_")
private String name;
@JsonProperty
@Column(name="category_")
private String category;
@JsonProperty
@Column(name="tenant_id_")
private String tenantId;
@JsonProperty
@Column(name="deploy_time_")
private Date deployTime;
@OneToOne (cascade=CascadeType.ALL)
@JoinColumn(name="deployment_id_", unique= true, nullable=true, insertable=true, updatable=true)
private ActivitiProcessDefinition activitiProcessDefinition;
//getters and setters
//tostring method
}
Класс ActivitiProcessDefinition:
@Entity
@Table(name="act_re_procdef")
public class ActivitiProcessDefinition implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@Column(name="id_")
@JsonProperty("process_def")
private String id;
@JsonIgnore
@Column(name="rev_")
private String rev;
@JsonProperty
@Column(name="category_")
private String category;
@JsonProperty
@Column(name="name_")
private String name;
@JsonProperty
@Column(name="key_")
private String key;
@JsonProperty
@Column(name="resource_name_")
private String resource_name;
@JsonProperty
@Column(name="version_")
private String version;
@JsonProperty
@Column(name="deployment_id_")
private String deploymentId;
@JsonProperty
@Column(name="dgrm_resource_name_")
private String diagramResourceName;
@JsonProperty
@Column(name="description_")
private String description;
@JsonProperty
@Column(name="has_start_form_key_")
private String hasStartFormKey;
@JsonProperty
@Column(name="has_graphical_notation_")
private String hasGraphicalNotation_;
@JsonProperty
@Column(name="suspension_state_")
private String suspensionState;
@JsonProperty
@Column(name="tenant_id_")
private String tenant_id_;
//getters and setters
//tostring method
}
}
Интерфейс репозитория:
@Repository
public interface ActivitiGetDeploymentRepository extends JpaRepository<ActivitiProcessDeployment, Long> {
public List<ActivitiProcessDeployment> findAll();
}
класс контроллера:
@RestController
@RequestMapping("/ProcessInfo/1.0.0")
public class RestController {
@ApiOperation(value = "getdeployments", notes = "This REST API is used to get deployments")
@GetMapping(value = "/getdeployments")
private List<ActivitiProcessDeployment> getdeployments() {
return ActivitiGetDeploymentRepository.findAll();
}
}
Ответ, который я получаю, включает в себя поле, хранящееся только в классе ActivitiProcessDeployment, но другой класс, который сопоставлен с классом ActivitiProcessDeployment, имеет нулевое значение.
[
{
"id": "2505",
"name": "newtest",
"category": null,
"tenantId": "-1234",
"deployTime": "2018-11-05T12:47:02.547+0000",
"activitiProcessDefinition": null
}
]
В приведенном выше ответе activitiProcessDefinition имеет значение null.
Ниже приведены данные таблицы. Столбец id_ в таблице act_re_deployment, с которым я связан, в столбце deploy_id_ таблицы act_re_procdef.
таблица act_re_deployment
id_ | name_ | category_ | tenant_id_ | deploy_time_ | activiti_process_definition_id_ | deployment_id_
------+---------+-----------+------------+-------------------------+---------------------------------+----------------
2505 | newtest | | -1234 | 2018-11-05 18:17:02.547 | |
act_re_procdef table
id_ | rev_ | category_ | name_ | key_ | version_ | deployment_id_ | resource_name_ | dgrm_resource_name_ | description_ | has_start_form_key_ | has_graphical_notation_ | suspension_state_ | tenant_id_
----------------+------+------------------------------+---------+---------+----------+----------------+--------------------+---------------------+--------------+---------------------+-------------------------+-------------------+------------
newtest:1:2508 | 1 | http://www.activiti.org/test | newtest | newtest | 1 | 2505 | newtest.bpmn20.xml | newtest.newtest.png | | f | t | 1 | -1234