• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

HQL Order By Class is not Sorting

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

I thought, we can do it in HQL itself.
 
That is a really big piece of pie for such a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic