我们现在使用spring-data-jpa(v1.10.2.RELEASE)和openjpa(v2.2.2),并且必须使用NULLS LAST执行ORDER BY查询,如下面的代码所示。
Sort.Order order = new Sort.Order(Direction.DESC, "latestConnectTime", NullHandling.NULLS_LAST);
Sort sort = new Sort(order);
PageRequest pageRequest = new PageRequest(1, 20, sort);
看起来EclipseLink和Hibernate已经支持这个功能了,但openjpa却没有?
https://jira.spring.io/browse/DATAJPA-825
https://jira.spring.io/browse/DATAJPA-925
https://jira.spring.io/browse/DATAJPA-1302
https://github.com/javaee/jpa-spec/issues/76
https://github.com/javaee/jpa-spec/issues/130
hibernate也通过EmptyInterceptor进行解决,或者只是将hibernate属性hibernate.order_by.default_null_ordering
配置为下面的链接。
Hibernate order by with nulls last
openjpa有没有办法解决ORDER BY NULLS LAST查询?