Reputation: 2019
I have 3 classes:
College:
id, name, ....
Student:
id, name, college, ....
Marks:
id, subject, student
I have collegeObject and list of students with me. I am able to query marks of a student in 2 ways:
JPA Property Expressions:
List<Marks> findByStudentCollege(College college)
.
Using In Query
List<Marks> findByStudentIn(Set<Student> studentList)
I need help in knowing which query is better to use from the performance perspective.
Upvotes: 0
Views: 177
Reputation: 26
You are executing two diferent queries:
findByStudentCollege(College college) : This one is going to be used to find the marks of the college, in every element "student" in the "college". You are not making a connection betweent marks and college so you'll probably will be doing a query like "select * from marks where student = (Select id from Student where college = (select from College) )
findByStudentIn(Set studentList) : This one is going to be used to find the marks in a list (0 or more "student" elements, so you need to list students before, or use it to find the marks of one student in focus.
The second one is probably the best option if you havent a complete list of students. If you have all the students of a college use the first one, because you are avoiding the first student list.
Anyway, you will not see the diference between these queries, even you are working with 5k+ rows
Upvotes: 1
Reputation: 124
you should try findByStudentCollegeId, it's better than pass the whole object for querying
Upvotes: 0