BabyGluk BabyGluk - 1 month ago 8
Java Question

Does not work query in spring data jpa

simple query findByPost with List work fine, but method where return Page does not work. Project even starts.When remove this method , All fine ;)

@Repository
public interface CategoryRepository extends CrudRepository<Category, Long>,
PagingAndSortingRepository<Category,Long> {

@Query("select c from Category c inner join fetch c.posts cp where cp.id =?1")
List<Category> findAllByPost(long postId);

@Query("select c from Category c inner join fetch c.posts cp where cp.id =?1")
Page<Category> findAllByPost(long postId, Pageable pageable);
}

Answer

You dont need to extend CrudRepository as PagingAndSortingRepository already does this. Change your signature to -

public interface CategoryRepository extends PagingAndSortingRepository