Given a JPA Repository as:
public interface CityRepository extends JpaRepository<City, Long>
And a method named:
public List<City> findFirst4ByHighlightedAndCountryCodeOrderByNameAsc(Boolean highlighted, String countryCode);
I'm getting this query:
select city0_.idCity as idCity1_2_, city0_.countryCode as countryC2_2_, city0_.highlighted as highligh3_2_, city0_.latitude as latitude4_2_, city0_.longitude as longitud5_2_, city0_.name as name6_2_, city0_.numPublishedItems as numPubli7_2_, city0_.idRegion as idRegion8_2_, city0_.url as url9_2_ from web_city city0_ where city0_.highlighted=? and city0_.countryCode=? order by city0_.name asc
As you can see, no limit is being applied. What I'm doing wrong?
Best How To :
Make sure you're using Spring Data JPA 1.7 or newer. This is usually done by setting the dependency version to the wanted version in e.g. your
<version>1.7.1.RELEASE</version> <!-- current version as of today -->
In the comments you listed 1.1.9 as used version, so I am assuming you're using Spring Boot to build your project. 1.1.9 of Boot still uses the Dijkstra release train of Spring Data, which means Spring Data JPA is included in version 1.6.4. To upgrade to the latest version configure a Maven property like this:
… <!-- other defined properties -->
This will upgrade Spring Data dependencies to the first service release of the Evans release train and include Spring Data JPA 1.7.1.