Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to retrieve data from associated table in ascenting order using crietria

 
john sal
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two bean classes..



Now I want to retrieve the Subject for a particular student in ascending order using creitria query. For doing the same first I have to retrieve the student object from the database, now i want that after getting the student object if I perform student.getSubjects() I get the list of all the subjects that has been taken by the particular statment in ascending order of subject name.

Can somebody let me know how to write a creitria query for the same.

Thanks
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To order a OneToMany use the @OrderBy annotation.

See,
http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Ordering

You cannot change an objects relationships based on a query.

You could query for the Subjects for a Student direct and order it however you wish in the query.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic