I'm trying to add to a list management with null values Results with null values must leave at the end. Add the option to the Order class in two different ways in the SQL query but nothing appears. I am using Oracle and if the consultation launched from a management database with null values results are listed at the end by default.
This is my code:
List<Order> orders = new ArrayList<Order>();
orders.add(new Order(Direction.DESC, "points"));
//THIS
orders.add(new Order(Direction.DESC, "person.date", NullHandling.NULLS_LAST));
//OR THIS
orders.add(new Order(Direction.DESC, "person.date").nullsLast());
//NOT WORKING
orders.add(new Order(Direction.DESC, "id"));
List<Foo> foos = fooRepository.findAll(new Sort(orders));
How I can specify that null results should go to the end?
Maybe is a little late but you can check this out (link).
In our case, we solved it using hibernate property hibernate.order_by.default_null_ordering
sugested by uwolfer; when we tried to use spring data function nulls last didn't work for us.
You can set this property in your Spring (Boot) application.yml
:
spring:
jpa:
properties:
hibernate.order_by.default_null_ordering: last
# or for first: hibernate.order_by.default_null_ordering: first
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With