• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

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:

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic