Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HQL Order By Class is not Sorting

 
Saravanan Vijayappan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Saravanan Vijayappan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could anyone please respond to this issue, I am still not able to solve it. Many Thanks in advance!!
 
Kuladip Yadav
Ranch Hand
Posts: 162
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you !!

I thought, we can do it in HQL itself.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic