I\'m trying to learn Spring on my own, and I\'m planning to do that by creating a blog web app. I already have the basic blog functionality working, which is a page to display b
I know it's a bit late but this may help others.
Just put BY
before ORDER
, like this: findAllByOrderByIdDesc
It should work.
There is an extension to CrudRepository called PagingAndSortingRepository
public interface PostRepository extends PagingAndSortingRepository<Post, Integer> {}
Then just call .findAll(new Sort(Sort.Direction.DESC, "id")); instead of findAllOrderByIdDesc();
May be my answer is stupid but did you try just "from Post order by id desc"
instead of "select p from Post p order by p.id desc"
I know I'm a little late to the game but..
Another fix would be to correct the syntax on your named query in your repository.
You have: Iterable<Post> findAllOrderByIdDesc();
When it should be: Page<Post> findAllByOrderByIdDesc();
Note the addition of the By
keyword after findAll
. This marks the beginning of your filtering statements.