1

How can I implement a method that return a page of objects using JpaRepository and not PagingAndSortingRepository ?

My repository

public interface GroupRepository extends JpaRepository<Group, Long> { @Query(value = "SELECT g FROM Group") Page<Group> listAllByPage(Pageable pageable); } 

My service implementation:

@Override public Page<Group> findGroupesByPagination(Pageable pageable) { return groupeRepository.listAllByPage(pageable); } 

My rest Controller method:

@RequestMapping(value="/groups", method = RequestMethod.GET) public @ResponseBody Page<Group> list( Pageable pageable){ Page<Group> groupes = groupeServiceImpl.findGroupesByPagination(pageable); return groupes; } 

Finally I got this error:

Error creating bean with name 'groupServiceImpl': Unsatisfied dependency expressed through field 'groupeRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'groupRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract org.springframework.data.domain.Page rimtrack.org.repository.GroupRepository.listAllByPage(org.springframework.data.domain.Pageable)!

5
  • 1
    Try to add 'g' after 'Group' in select query: "select g from Group g" Commented Apr 14, 2017 at 10:22
  • yes thanks this is the right answer Commented Apr 14, 2017 at 10:26
  • Don't forget to +1 my comment ;) Commented Apr 14, 2017 at 11:03
  • yes i would like but how to do it ??? Commented Apr 14, 2017 at 11:36
  • Click on the up-arrow on the left of my comment )) Commented Apr 14, 2017 at 11:38

1 Answer 1

3

The query can be defined by an annotation somewhere or declared by other means. Consult the documentation of the specific store to find available options for that store. If the repository infrastructure does not find a declared query for the method at bootstrap time, it fails.

You should using Spring Data Jpa method. Reference

 Page<T> findAll(Pageable pageable); 

Please change repository class.

Exam:

public interface GroupRepository extends JpaRepository<Group, Long> { Page<Group> findAlll(Pageable pageable); } 
Sign up to request clarification or add additional context in comments.

10 Comments

thanks for your response but i got the same error what should i do please help
Please write full stack trace.
what does you mean by full stack trace. #jackk??
Console Error messages.
Did you changed GroupRepository class.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.