What I want to do is "get all schools with its students" but It doesn't initialize student list. Some people says change it to FetchType.EAGER but I have no choice like updating it and also I don't think its a solution. Is there a way to initialize it?
@Service
public class SchoolService {
@Autowired
private SchoolRepository schoolRepository;
public List<School> getAllSchools() {
return schoolRepository.findAll();
}
}
public class School {
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "school_student", joinColumns = {@JoinColumn(name = "school_id")},
inverseJoinColumns = {@JoinColumn(name = "student_id")})
private List<Student> students= new ArrayList<>();
...
}
EDIT: I am using spring data jpa 1.10.1