-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: SQL order by ... nulls first
PostPosted: Wed Jan 12, 2011 1:39 pm 
Beginner
Beginner

Joined: Mon Mar 01, 2010 12:24 pm
Posts: 22
Hello everybody,

I want to sort my objects either ascending or descending but by adding null sort at the end of the result. I found that it is possible to do it using JDBC by either adding ORDER BY myField NULLS LAST but it does not work using MS SQLServer or MySQL. I found a workaround to do the same without using NULLS LAST.

But my question is : How can I sort my result using Hibernate in order to put null values at the end of my sort?
Is there a way to inject in the HQL query NULLS LAST? because Hibernate deletes NULLS LAST before querying the database.

Thanks in advance,
Matti


Top
 Profile  
 
 Post subject: Re: SQL order by ... nulls first
PostPosted: Thu Jan 13, 2011 9:04 am 
Newbie

Joined: Thu Jan 13, 2011 6:15 am
Posts: 1
Hello,

I have the same problem. I saw that a bug is reported on that, but it's always marked as unresolved.

Thanks,
Elias


Top
 Profile  
 
 Post subject: Re: SQL order by ... nulls first
PostPosted: Thu Jan 13, 2011 12:31 pm 
Beginner
Beginner

Joined: Tue Oct 26, 2010 6:12 pm
Posts: 29
Quote:
Is there a way to inject in the HQL query NULLS LAST? because Hibernate deletes NULLS LAST before querying the database.


Did you try following the work-around that is mentioned in the bug? That seems like a quick fix that should work...


Top
 Profile  
 
 Post subject: Re: SQL order by ... nulls first
PostPosted: Wed Jan 19, 2011 1:05 pm 
Beginner
Beginner

Joined: Mon Mar 01, 2010 12:24 pm
Posts: 22
Hello,
Thanks for your answer. Yes I try the workaround and I use it until a better choice. I find that parsing the SQL query and adding NULLS FIRST or LAST depending on the sort is not the best solution but it works. Quite hard to use it with SQLServer especially with SELECT DISTINCT request but it works.

Thanks,
Matti


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.