2017-06-06 120 views
0

我想执行以下查询:SQLGrammarException:无法提取的ResultSet

@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 

我如何descac之间进行选择在此查询?

+1

添加完整的堆栈跟踪。通过查询顺序排列的占位符通常也不受支持(尽管它可能因您的JDBC驱动程序而异)。要订购,您可以通过'Sort'类作为方法的最后一个参数。 –

+0

谢谢,但是如何查询,@Query(value =“update car_wash set lon_lat = ST_GeomFromText('POINT(:lon:lat)')where id =:id;”,nativeQuery = true) void upateLonLat( Double lon,Double lat,Integer id); 我需要知道如何把参数,查询,你有什么建议吗? –

+0

这是一个不同的问题。此外,为什么你需要更新查询?首先击败JPA的目的,看起来你正在JPA而不是使用JPA。 –

回答

0

有一种方法可以将Pageable用于原生查询。如果Pageable中存在Sort对象,则弹簧数据将追加到请求“order by”的末尾。

List<WashHistory> findDesc(Integer carWashId,String descOrAsc, Pageable pageable); 
相关问题