嗯,我有一个非常简单的方法,它应该返回一些代码...而且确实如此,但顺序并不起作用。
private List<Code> get(String qualifier, ZonedDateTime validAt) {
return em.createQuery(
"select c\n"
+ " from Code c\n"
+ " where c.qualifier = :qualifier\n"
+ " and c.validFrom <= :validAt)\n"
+ " and c.validUntil > :validAt)\n"
+ " order by c.sequence, c.code\n",
com.service.code.impl.model.Code.class)
.setParameter("qualifier", qualifier)
.setParameter("validAt", validAt)
.getResultList().stream()
.map(converter::convert)
.collect(Collectors.toList());
}
当我调用方法时,我会记录语句,这就是它的样子:
07:59:44,158 INFO [stdout] (default task-15) Hibernate:
07:59:44,158 INFO [stdout] (default task-15) select
07:59:44,158 INFO [stdout] (default task-15) code0_.id as id1_0_,
07:59:44,159 INFO [stdout] (default task-15) code0_.changed_at as changed_at2_0_,
07:59:44,159 INFO [stdout] (default task-15) code0_.changed_by as changed_by3_0_,
07:59:44,159 INFO [stdout] (default task-15) code0_.created_at as created_at4_0_,
07:59:44,159 INFO [stdout] (default task-15) code0_.version as version5_0_,
07:59:44,159 INFO [stdout] (default task-15) code0_.code as code6_0_,
07:59:44,163 INFO [stdout] (default task-15) code0_.description as description7_0_,
07:59:44,163 INFO [stdout] (default task-15) code0_.qualifier as qualifier8_0_,
07:59:44,163 INFO [stdout] (default task-15) code0_.sequence as sequence9_0_,
07:59:44,163 INFO [stdout] (default task-15) code0_.valid_from as valid_from10_0_,
07:59:44,163 INFO [stdout] (default task-15) code0_.valid_until as valid_until11_0_
07:59:44,163 INFO [stdout] (default task-15) from
07:59:44,163 INFO [stdout] (default task-15) code code0_
07:59:44,163 INFO [stdout] (default task-15) where
07:59:44,163 INFO [stdout] (default task-15) code0_.qualifier=?
07:59:44,164 INFO [stdout] (default task-15) and code0_.valid_from<=?
如您所见,缺少订单。怎么可能呢?
答案 0 :(得分:2)
你应该从最后两行中删除)
,如下所示;)
private List<Code> get(String qualifier, ZonedDateTime validAt) {
return em.createQuery(
"select c\n"
+ " from Code c\n"
+ " where c.qualifier = :qualifier\n"
+ " and c.validFrom <= :validAt\n"
+ " and c.validUntil > :validAt\n"
+ " order by c.sequence, c.code\n",
com.service.code.impl.model.Code.class)
.setParameter("qualifier", qualifier)
.setParameter("validAt", validAt)
.getResultList().stream()
.map(converter::convert)
.collect(Collectors.toList());
}