Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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

Multiple Object Select Problems

Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have School and Student table .
There is a one to many relationship. One school can have many students
Now when I wite a SQL query to the School table to get the complete school info.

Now this query returns me a school which has a student which is the eldest age wise in the entire studdnt table.

so when I run the sql it would give me 1 School record.

In that record I want to display student name also

Now when I execute the same in Hibernate it works just fine it gives me just one School object which is what I want but when I need to retrieve the student information from there which has One to many mapping means School would have getStudents() which returns a list of students when I do that it doesnt return me just the student which has the max age but it returns all the students which belong to that school.

so If the school has 3 rows with school id 1 2 3 and student has 150 rows with 50 students belonging to school 1 and other 50 belonging to school 2 and the rest 50 to school 3 so school_1 getStudents will return me 50 students and not just the studnet which has the max age as was specified in the criteria although it returns me the correct and only 1 school object but not the case with the linked classes

can you please provide me some insight on the same

I am currently using Criteria objects for querying

Some one suggested using Hibernate Report queries

Navin Keswani
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic