我想执行以下查询:
@Query(value = "select * from wash_history w where w.wash_id IN \n"
+ "(select w.id from wash w where w.car_wash_id=?1) order BY w.time
?2", nativeQuery = true)
List<WashHistory> findDesc(Integer carWashId,String descOrAsc);
但我有以下错误
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause
如何在此查询中选择desc
或ac
?
答案 0 :(得分:0)
有一种方法可以将Pageable
与原生查询结合使用。 Spring数据将追加到您的请求结束时#34;按顺序排列&#34;如果Sort
中有Pageable
个对象。
List<WashHistory> findDesc(Integer carWashId,String descOrAsc, Pageable pageable);