设立一个JPA仓库,作为:
public interface CityRepository extends JpaRepository<City, Long>
还有一个名为:
public List<City> findFirst4ByHighlightedAndCountryCodeOrderByNameAsc(Boolean highlighted, String countryCode);
我收到了这样的查询:
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
正如你所看到的,没有任何限制被应用。我做错什么了?
发布于 2014-12-10 05:32:01
确保您使用的是SpringDataJPA1.7或更高版本。这通常是通过将依赖版本设置为想要的版本来完成的,例如,您的pom.xml
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.7.1.RELEASE</version> <!-- current version as of today -->
</dependency>
在注释中,您列出了1.1.9作为用过的版本,所以我假设您正在使用Spring构建项目。1.1.9 Boot仍然使用Spring数据的Dijkstra发布序列,这意味着版本1.6.4中包含了Spring数据JPA。要升级到最新版本,请配置如下所示的Maven属性:
<properties>
… <!-- other defined properties -->
<spring-data-releasetrain.version>Evans-SR1</spring-data-releasetrain.version>
</properties>
这将将Spring数据依赖项升级到Evans发布系列的第一个服务版本,并包括SpringDataJPA1.7.1。
发布于 2014-12-09 04:24:51
你能试一下下面的语法吗?这可能对你有帮助。
List<User> findFirst10ByHighlightedAndCountryCode(Boolean highlighted, String countryCode, Sort sort);
并提供排序顺序来排序参数。
希望这对你有帮助
https://stackoverflow.com/questions/27377794
复制相似问题