Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Fetch data using single select statement in HQL (Many to One relationship)  RSS feed

 
sameer verma
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two entities student and college. A single college has multiple student.


I want to fetch all the students of a particular college.

As you can see in below code the HQL query I have written is : "select student from "+Student.class.getName()+" student where student.college.collegeId = 1"

On execution of following code I two SQL queries are fired as follows:


Ideally first query is sufficient to fetch all required students and it is working well when I fire directly from database.

why second query is executed? How can I stop Hibernate by executing this extra query?
Utility class:


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!