我有一个针对Employee和Department类的Spring Rest Data的实现。但是当我尝试使用rest模板获取数据时,两个实体的id总是为空,但是使用调用hibernate方法时,它会填充所有数据。我有什么遗漏代码吗?
员工
@Entity
public class Employee {
@Id @GeneratedValue
@Column(name="id")
private Long id;
@Column(name="name")
private String name;
@OneToOne(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
@JoinColumn(name="department_ID")
private Department department;
//Getters Setters
系
@Entity
public class Department {
@Id @GeneratedValue
@Column(name="id")
private Long id;
@Column(name="name")
private String name;
@OneToOne(mappedBy="department")
private Employee employee;
// Getters setters
休息电话
ResponseEntity<Resources<Employee>> empResponse = restTemplate.exchange(url, HttpMethod.GET, null,
new ParameterizedTypeReference<Resources<Employee>>() {});
在api调用期间执行查询
Hibernate: select employee0_.id as id1_1_0_, employee0_.department_id as departme3_1_0_, employee0_.name as name2_1_0_, department1_.id as id1_0_1_, department1_.name as name2_0_1_ from employee employee0_ left outer join department department1_ on employee0_.department_id=department1_.id where employee0_.id=?