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 Retereive data by ORDER BY Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Retereive data by ORDER BY" Watch "Retereive data by ORDER BY" New topic

Retereive data by ORDER BY

Mike Boota
Ranch Hand

Joined: Jul 18, 2002
Posts: 82
Hi I need a small help in getting the data as per the order it's entered in the table. I am building a menu that has sub-menus.
In SUB_MENU table I also have a order_by column and in my hbm.xml file I specify orderby on that column it returns me data in correct order.

ParentMenu does not have order_by column how can I get the data ordered by on id column for my ParentMenu i.e. a sequence. Or do I need a order_by column in ParentMenu table and then specify ordyby on that column too.


MB<br />Sun Certified Programmer for Java2 Platform
Mike Boota
Ranch Hand

Joined: Jul 18, 2002
Posts: 82
Any idea how I can achieve this. Thanks
newbie awo

Joined: Feb 09, 2005
Posts: 4
What happens if you try adding something like sort="MyComparatorClass" to the set of SubMenus (in the ParentMenu mapping)?

(Then you could implement a class which implements java.util.Comparator and whose compareTo method allows the SubMenu objects to be sorted by the property that maps to your order-by column.)
[ September 06, 2006: Message edited by: newbie awo ]
Mike Boota
Ranch Hand

Joined: Jul 18, 2002
Posts: 82
My Sub Menu is in order as I have

<set name="subMenu" table="SUB_MENU" order-by="ORDER_BY">

But the issue is how to get the data ordered by id column on my Parent Menu. id is a number field in my Menu Table. That is my Parent menu is not ordered. e.g. in my Parent Menu table If I have the following data

A 32
B 2
C 4

it shows up in that order, but I would like to see it in the following order i.e. order by id


I agree. Here's the link:
subject: Retereive data by ORDER BY
It's not a secret anymore!