0

In my app I want to add to my pageable object I want to add order null first for selected attribute. I have followed this advice on stack overflow: How to use Pageable as get-query parameter in spring-data-rest?

Like this:

private Pageable customSort(Pageable pageable) {
    Sort sort = pageable.getSort();
    Order order = sort.iterator().next();
    List<Order> orders = new ArrayList<>();
    orders.add(new Order(order.getDirection(),order.getProperty()).nullsFirst());
    return PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by(orders));
} 

But my problem is that we use SQL Server database which does not support nulls first sorting. (as you can see here: TSQL ORDER BY with nulls first or last (at bottom or top))

Is there any workaround how to modify pageable request for SQL Server database?

Dale K
  • 25,246
  • 15
  • 42
  • 71
Michael
  • 33
  • 5
  • Have you actually tried this code to see the results? I suspect that the JPA dialect simulates this with some tricks (or Spring Data JPA does it). – M. Deinum Jan 09 '20 at 07:39
  • Yes i have tried it, it looks like it is ommited in sql result: ...order by myobject.attribute desc offset 0 rows fetch next ? rows only – Michael Jan 09 '20 at 07:56
  • Please add your repository and confiugration to your question. – M. Deinum Jan 09 '20 at 07:57

0 Answers0