aspose file tools*
The moose likes Object Relational Mapping and the fly likes HQL Order By Class is not Sorting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "HQL Order By Class is not Sorting" Watch "HQL Order By Class is not Sorting" New topic
Author

HQL Order By Class is not Sorting

Saravanan Vijayappan
Ranch Hand

Joined: Jan 02, 2007
Posts: 47
Hello,

I have 2 entity classes, Menugrop and Catgroup. Mengroup has one to many relationship with Catgroup. In Mengroup,
private Collection<Catgroup> catgroups = new LinkedHashSet<Catgroup>();

I write the below code to fetch Menugroup and it's catgroup.




Hibernate generates the below SQL.



The result is below:

Menu name - Computer: Personal Electronics ,Home Audio ,A/V Essentials ,Hard Drive ,Monitor & Projector ,Computers ,Flash Memory

Menu name - Electronics: Networking ,CDs/DVDs ,Components

Menu name - Phone: Books ,MP3 Players ,Home Appliances ,Power Protection ,Cameras & Photo,Printers & Scanners

When we look at the Catgroups in the Menu in the result, they are not sorted by Catgroup.name

As I use linkedHashSet, I am expecting the sorting to work, but, it did not happen?

Can anyone please suggest me what do it need to correct to make the results in ordered format?

Thanks
[ November 01, 2008: Message edited by: Saravanan Vijayappan ]

Cheers,<br />Sarav
Saravanan Vijayappan
Ranch Hand

Joined: Jan 02, 2007
Posts: 47
Could anyone please respond to this issue, I am still not able to solve it. Many Thanks in advance!!
Kuladip Yadav
Ranch Hand

Joined: Jul 30, 2008
Posts: 162

Hi Saravanan ,

You have to implement Camparator for Catgroup class and

and set sort attribute in Menugroup.hbm.xml for catgroups


Your comparator class may be like this :



You can modify Menugroup.hbm.xml as




Hope this will work.

Thanks

- Kuldeep
Saravanan Vijayappan
Ranch Hand

Joined: Jan 02, 2007
Posts: 47
Thank you !!

I thought, we can do it in HQL itself.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HQL Order By Class is not Sorting