I am using Spring JPA. I have three entities Student, ClassRoom and School like below
@Entity
public class Student implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="id")
private int id;
@Column(name="name")
private String name;
@Column(name="name")
private int age;
...
}
@Entity
public class ClassRoom implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="id")
private int id;
@Column(name="name")
private String name;
@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name="id")
private List<Student> students;
...
}
@Entity
public class School implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="id")
private int id;
@Column(name="name")
private String name;
@OneToMany
@JoinColumn(name="id")
private List<ClassRoom> classRooms;
...
}
Now I am fetching School with ClassRoom details and I don't need Student details.
But Student entity in ClassRoom is set to Fetch Type EAGER. How can I get School records with ClassRoom records without Student records.
Note: I can't remove FetchType.EAGER on Student Entity.