我正在使用数据表 jQuery插件来显示顺序列表。在调试我的应用程序时,我偶然发现了以下不一致之处。
为了检索数据,我使用@Query-Notation进行自定义查询:
@Query("select op from OrderPosition " +
"op where op.order.created >= ?1" +
" and op.depot in ?2" +
" and op.order.deliveryAddress.deliveryMode in ?3" +
" and op.pickStatus in ?4 and op.order.id like ?5 ")
Page<OrderPosition> findOrderpositionsByFilterStatus(Date date, List<Integer>depots, List<DeliveryMode> deliveryModes, List<ArticleStatusType> pickStatus, String sSearch, Pageable p);发生的错误如下:
我有一套81个订单测试数据。在前面,我能够通过几个标准进行过滤。其中的标准之一是deliveryMode (快递标准)。我一次显示10个条目。express传递的总数为6。在分页时,只显示2 express。当在express上进行明确的过滤时,我得到了全部6。
当我添加某种排序时,例如:
@Query("select op from OrderPosition " +
"op where op.order.created >= ?1" +
" and op.depot in ?2" +
" and op.order.deliveryAddress.deliveryMode in ?3" +
" and op.pickStatus in ?4 and op.order.id like ?5 " +
"order by op.order.id desc")
Page<OrderPosition> findOrderpositionsByFilterStatus(Date date, List<Integer>depots, List<DeliveryMode> deliveryModes, List<ArticleStatusType> pickStatus, String sSearch, Pageable p);我拿到了所有的六个。
为什么我要问这个问题:
当使用非注释查询时--无论是泛型findAll()还是来自方法名称的查询--Spring JPA在检测pageable时是否在内部使用order by-clause?或者逆:在使用order by时,是否必须在每个自定义查询中添加一个pageable
发布于 2013-09-12 13:29:37
是的。如果不进一步指定,Spring数据将使用OrderBy (带有默认的desc)。看看这些日志:
SELECT t0.oid, t0.jpaversion, t0.amount, [...]
FROM [...]
WHERE [..] AND (t13.jpatype IS NULL OR t13.jpatype IN (?))
ORDER BY t0.oid DESC LIMIT ?, ?https://stackoverflow.com/questions/18741730
复制相似问题