I have a repository interface with some abstract methods where I use the @Query annotation.
Now I would like to add limit and offset support to this queries.
example:
public interface ProductRepository
extends CrudRepository<Product, Long> {
@Query("from Product")
List<Product> findAllProducts();
}
something like this would be nice
public interface ProductRepository
extends CrudRepository<Product, Long> {
@Query("from Product limit :limit ")
List<Product> findAllProducts(@Param("limit") Integer limit);
}
But this doesn’t work. There is a solution that I create an implementation of the interface (http://stackoverflow.com/questions/3479128/jpql-limit-number-of-results)
But I wonder if there is not a possibility of adding offset and limit to the query or if there is an annotation for this.
limitis not supported by JPQL. Even without it your queries are not valid JPQL queries (but may be valid HQL – and may work if your JPA provider is tolerant).A (partial) implementation is needed so you can use the
Queryinterface or the criteria api.