11

I need my data to be ordered by null and not null only. Like below:

Column A
null 
null 
null
8 
10
5

Meaning once all the null values are on top, the rest of the values should not be sorted at all and come as is. Any idea how this can be done using jpa query/ native query.

Oliver Drotbohm
  • 80,157
  • 18
  • 225
  • 211
Priyabrat Nanda
  • 1,095
  • 3
  • 18
  • 34

2 Answers2

9

If you project use Spring Boot, you can add YML configuration like this, it work for me.

spring:
  jpa:
    properties:
        hibernate.order_by.default_null_ordering: last
hang gao
  • 421
  • 5
  • 6
4

Use JPQL and you will be happy.

SELET f FROM Foo f ORDER BY f.name NULLS LAST