NullHandling.NULLS_LAST不起作用

osc*_*car 5 sql spring hibernate spring-data spring-data-jpa

我正在尝试添加具有空值的列表管理,具有空值的结果必须保留在最后。在SQL查询中以两种不同的方式将选项添加到Order类,但是什么也没有出现。我使用的是Oracle,如果默认情况下从管理数据库启动的咨询具有空值结果,则将其列出。

这是我的代码:

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));
Run Code Online (Sandbox Code Playgroud)

如何指定空结果应该结尾?

Rog*_*nco 9

也许有点晚了,但是您可以检查一下(链接)。

在我们的案例中,我们使用hibernate.order_by.default_null_orderinguwolfer产生的休眠属性解决了该问题;当我们尝试使用spring数据函数null时,last对我们不起作用。

您可以在Spring(启动)中设置此属性application.yml

spring:
    jpa:
        properties:
            hibernate.order_by.default_null_ordering: last
            # or for first: hibernate.order_by.default_null_ordering: first
Run Code Online (Sandbox Code Playgroud)


小智 0

我遇到同样的问题。

List<Sort.Order> orderList = new ArrayList<Sort.Order>();
    orderList.add(new Sort.Order(Sort.Direction.DESC,"landArea",nullHandling.NULLS_LAST));

    Pageable pageable = new PageRequest(0, PAGE_SIZE, new Sort(orderList));
    Page<SearchSvcAttribsEntity> PropertySearchEntityList =
            searchSvcAttribsRepository.findAll(PropertySearchSvcAttribsSpecs.findByCriteria(propertySearchCriteria), pageable)
Run Code Online (Sandbox Code Playgroud)

;

应该生成 sql: order by desc nulls last 但生成: order by desc (最后去掉 null)

我正在使用这个依赖项:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    <version>1.3.3.RELEASE</version>
</dependency
Run Code Online (Sandbox Code Playgroud)