简体   繁体   English

如何使用spring数据jpa Sort.Order.nullslast

[英]how to use spring data jpa Sort.Order.nullslast

I used nullslast() as the sample code as below, 我使用nullslast()作为示例代码,如下所示,

        List<Sort.Order> orders = new ArrayList<>();

        Sort.Order orderAuditTime = new Sort.Order(Sort.Direction.DESC,"auditTime");
        Sort.Order orderEntryTime = new Sort.Order(Sort.Direction.DESC,"customer.entryTime");

        orders.add(orderAuditTime.nullsLast());
        orders.add(orderEntryTime);

        sort = new Sort(orders);

but got sql without nulls last like : 但最后得到的sql没有空值:

order by
    auditrecor0_.audit_time desc,
    customer1_.entry_time desc limit ?

Can someone help me why orderAuditTime.nullsLast() doesn't work ? 有人可以帮我解释为什么orderAuditTime.nullsLast()不起作用?

The database is postgre and the orm framework is hibernate. 数据库是postgre,orm框架是hibernate。

As far as I can see, instances of Sort.Order get converted to javax.persistence.criteria.Order. 据我所知,Sort.Order的实例转换为javax.persistence.criteria.Order。 This interface does not have support for nulls first/last: 此接口首先/最后不支持空值:

package javax.persistence.criteria;

public interface Order {
    Order reverse();
    boolean isAscending();
    Expression<?> getExpression();
}

Thus, nulls first/last specified on Sort.Order is ignored. 因此,将忽略Sort.Order上指定的第一个/最后一个空值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Spring Data Jpa中使用自然排序 - How to use natural sort with Spring Data Jpa 如何对 spring jpa 中的数据进行排序? - How to sort data in spring jpa? 如何使用QueryDSL在Spring Data JPA中使用order by和Limit - How to use order by and Limit in Spring Data JPA using QueryDSL 使用具有 jpa 规格的 spring 数据按特定顺序按多个值排序 - Sort by multiple values in specific order using spring data with jpa specifications Spring Data JPA-排序依据:方法名称排序与排序类 - Spring Data JPA - Order By : Sorting with Method Name vs Sort Class 最后在哪里找到如何将sort.order.ignorecase()与null处理null一起使用的示例,以自定义Spring JPA如何提供查询 - Where to find examples of how to use sort.order.ignorecase() with nullhandling nulls last to customize how Spring JPA serves up queries 如何按Spring数据JPA查询中的多列排序并按顺序进行计算? - How to order by multiple columns in Spring data JPA query with calculation in order by? 使用Spring Data JPA进行复杂排序 - Complex Sort with Spring Data JPA Spring数据JPA:如何使用@PathVariable和JPQL - Spring Data JPA : How to use @PathVariable and JPQL 如何在一个简单的Servlet中使用Spring Data JPA? - How to use Spring Data JPA in a simple Servlet?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM