This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Criteria API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Criteria API" Watch "Criteria API" New topic

Criteria API

Mateusz Kwasniewski

Joined: Apr 18, 2006
Posts: 15
I'd like to get a list of subcategories in order (asc or desc) specified by the number of books in a subcategory. Can anyone help me to figure out how can I do it using Hibernate Criteria API?

Here is the code of the Subcategory class:

Thanks in advance

SCJP5 - 90%<br />SCWCD - 91%
Edvins Reisons
Ranch Hand

Joined: Dec 11, 2006
Posts: 364
What if you approach this matter from the Book end of the association?
Group them by Subcategory and order by rowCount.
saranga rao
Ranch Hand

Joined: Apr 24, 2007
Posts: 49
hi ,

Might it look like this.......

List lst = session.createCriteria(SubCategories.class).createAllias("Book","bk").add(Expression.eq("",id).add(Order asc);

May there will be change in the Allias name but the query returns list of SubCategories.....
jQuery in Action, 2nd edition
subject: Criteria API
Similar Threads
EJB 3.0 and ManyToMany relationship
Sort collection using one-to-one field
object cloning
ArrayList Problem while parsing XML...
Collections heirarchy