File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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.....
I agree. Here's the link:
subject: Criteria API
It's not a secret anymore!