Order By Date ASC with Spring Data

匿名 (未验证) 提交于 2019-12-03 02:50:02

问题:

I try to make an application with Spring-Data-JPA on a table in order by ASC but it gives me an error:

Invalid derived query! No property asc found for type java.util.Calendar 

Why ?

List<Foo> findAllOrderByDateAsc(); 

or

@Query("SELECT * FROM foo ORDER BY date ASC") List<Foo> findAllOrderByDateAsc(); 

回答1:

Try to add "By" between "All" and "Order" like this:

List<Foo> findAllByOrderByDateAsc(); 


回答2:

I don't think you can use findAll as a prefix.

Regarding the query, select * is not valid JPQL. It should be

select foo from Foo foo order by foo.date desc 


回答3:

date is reserved word in SQL. Try changing the table property to foo_date, for example and rewrite your query as SELECT * FROM foo ORDER BY foo_date DESC



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!