Grails / Hibernate: how to order isnull (property) to get NULLs for the last time?

Usually when ordering an increase in a field, you first get NULL values, and then more interesting values. Often you need NULL values. In MySQL, you can do this with:

SELECT * FROM people ORDER BY ISNULL(name), name;

However, I use Grails with Hibernate criteria, and I have absolutely no idea how to do this. Is it even supported? Is there a way to order a custom SQL expression? I would really like to rewrite all my criteria in plain SQL so that it is sorted correctly.

+5
source share
3 answers

HibernateCriteriaBuilder, NullPrecedence GORM, AbstractHibernateCriteriaBuilder order(), org.hibernate.criterion.Order Hibernate

     People.createCriteria().list (){
          order(org.hibernate.criterion.Order.asc('name')
                . nulls(org.hibernate.NullPrecedence.LAST)
           )
     }
+4

, Hibernate: .

, NativeSQLOrder HibernateCriteriaBuilder. sqlOrder HibernateCriteriaBuilder, , HibernateCriteriaBuilder.order().

+2

:

c =...;

c.addOrder(Order.asc( "" ) (NullPrecedence.LAST).);

+2

All Articles