Lazy loading is not working in OnetoMany Jpa relations

Viewed 33

Below are my entity classes Instructor and Courses having OnetoMany Relations, where all CRUD Operation is working but while fetching Instructor I don't want courses to be fetched. But when I execute GET instructor By Id, It also fetches courses in Postman. This should be avoided.

public class Instructor {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;
    private String firstName;
    private String lastName;
    private String email;

   @OneToMany(mappedBy = "instructor", cascade = {CascadeType.ALL})
   @JsonManagedReference
   private List < Course > courses;
}

public class Course {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String title;

    @ManyToOne(fetch =FetchType.LAZY)
    @JoinColumn(name = "instructor_id")
    @JsonBackReference
    private Instructor instructor;
 }
0 Answers
Related