5.3.9. 应用查询提示

5.3.9. 应用查询提示

5.3.9. Applying Query Hints

为了在库接口声明的查询上应用JPA查询提示,可以使用@QueryHints注解。接收参数为JPA @QueryHint注解数组,和一个为了在应用分页时,用于失效提示应用被计数查询触发的布尔值,如下例所示:

To apply JPA query hints to the queries declared in your repository interface, you can use the @QueryHints annotation. It takes an array of JPA @QueryHint annotations plus a boolean flag to potentially disable the hints applied to the additional count query triggered when applying pagination, as shown in the following example:

例66. 在库方法上使用QueryHints

Example 66. Using QueryHints with a repository method

public interface UserRepository extends Repository<User, Long> {

  @QueryHints(value = { @QueryHint(name = "name", value = "value")}, forCounting = false)
  Page<User> findByLastname(String lastname, Pageable pageable);
}

上面的声明将会为查询应用配置的@QueryHint,但不会应用到计算分页总数触发的计数查询。

The preceding declaration would apply the configured @QueryHint for that actually query but omit applying it to the count query triggered to calculate the total number of pages.

翻译部分版权归YahaCode团队所有。仅供学习研究之用,任何组织或个人不得私自以此用于任何形式的商业目的

发表评论