Hibernate order by with nulls last

前端 未结 7 2097
谎友^
谎友^ 2020-11-30 03:42

Hibernate used with PostgreSQL DB while ordering desc by a column puts null values higher than not null ones.

SQL99 standard offers keyword \"NULLS LAST\" to declare

7条回答
  •  粉色の甜心
    2020-11-30 04:32

    We can create Pageable object with following Sort parameter:

    JpaSort.unsafe(Sort.Direction.ASC, "ISNULL(column_name), (column_name)")
    

    We can prepare HQL as well:

    String hql = "FROM EntityName e ORDER BY e.columnName NULLS LAST";
    

提交回复
热议问题