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 sort with NULL

 
Davie Lin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I was wondering how to do the above

currently I have



rather than



So the problem I am having is that I am required to sort by name, not id
however, my HQL will not return the myParentClass if myChildClass is null, but it will return the myParentClass if myChildClass is null and sort on id.

I have looked up in SQL where you would put



but I have try



and it's not working. Can someone help me out with this issue?

Thanks, much appreciated



 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think HQL can specify how nulls are sorted. I don't think all databases supprot this syntax so HQL can't. Could you sort in Java rather then on the database?
 
Davie Lin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see the point of using Java to sort if HQL does not return the row with myParentClass is null when I sort on myParentClass.name.

I am required to sort from Database level, not Java level and I think would be more difficult to sort in Java level for me anyways. Now to be clear, I don't need Null to be first or last, I just need HQL to display the rows with myParentClass is null. is it really not possible?

Thanks for your reply
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic