jQuery in Action, 3rd edition
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 REST with Spring (video course) this week in the Spring 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("bk.id",id).add(Order asc);

May there will be change in the Allias name but the query returns list of SubCategories.....
I agree. Here's the link: http://aspose.com/file-tools
subject: Criteria API
jQuery in Action, 3rd edition