1

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=?
  • I'm voting to close this question as off-topic because the user has essentially re-asked the same question here: https://stackoverflow.com/questions/50798326/spring-data-rest-will-export-all-its-attributes-except-the-id – Alan Hay Jun 12 '18 at 08:31
  • Possible duplicate of [Spring boot @ResponseBody doesn't serialize entity id](https://stackoverflow.com/questions/24839760/spring-boot-responsebody-doesnt-serialize-entity-id) – lcnicolau Jul 06 '18 at 18:55

0 Answers0