I have EmbeddedId which has field which need to be loaded lazy. In service class on fetching TeacherStudent it also fetch student EAGERLY which should be LAZY fetch. what changes are needed to make student being fetched as lazy ?
TeacherStudent.class —> making student load as lazy
class TeacherStudent
{
public static final String TEACHER = "TeacherStudentPk.teacher";
public static final String STUDENT = "TeacherStudentPk.student";
@EmbeddedId
TeacherStudentPk teacherStudentPk = new TeacherStudentPk();
@ToString.Exclude
@Transient
Teacher teacher;
@ToString.Exclude
@Transient
Student student;
}
Getting Teacher Student data from teacher table
TeacherStudentpk.class
@Embeddable
class TeacherStudentPk{
@ManyToOne(fetch = FetchType.LAZY , optional = false)
@JoinColumn(name = "student_pk")
Student student; **<------------- student marked as lazy**
Teacher teacher;
}
TecherService.class
class TeacherService{
void getTeacherStudent(Teacher teacher){
Set<TeacherStudent> teacherStudent =
teacher.getTeacherStudent(); **<-----eager
fetching student which is of lazy type**
}
}
How should I change in classes to make student as fetch lazy ?