I have an implementation with Spring Rest Data for a Employee and Department class. However when I try to fetch the data using rest template, the id is always comes null for both the entities but with calling hibernate methods, it populating all the data. Is there anything I am missing to code ?
Employee
@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
Department
@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
Rest Call
ResponseEntity<Resources<Employee>> empResponse = restTemplate.exchange(url, HttpMethod.GET, null,
new ParameterizedTypeReference<Resources<Employee>>() {});
Query executing during api call
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=?