Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NullHandling.NULLS_LAST not working

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?

like image 632
oscar Avatar asked Mar 16 '16 12:03

oscar


1 Answers

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
like image 69
Rogelio Blanco Avatar answered Sep 17 '22 20:09

Rogelio Blanco