Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPQL Query Annotation with Limit and Offset

Tags:

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.