本文介绍了如何在默认Spring Data JPA方法上添加QueryHints?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以将Query Cache和Spring Data JPA一起用于以下自定义查询方法.
I am able to use Query Cache with Spring Data JPA for my custom query methods like below.
public interface CountryRepository extends JpaRepository<Country, String> {
@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
Country findByCountryName(String countryName);
@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
Country findByCountryCode(String countryCode); }
但是,如何在现有的父方法(如findAll())上添加@QueryHints?
However, how to add @QueryHints on existing parent methods like findAll()?
谢谢.
推荐答案
findAll(),findOne()等不是查询.这些实体上的所有缓存规范都将在这些方法中生效.
findAll(), findOne() etc. are not Query(s). Any caching specifications on the entity take effect in these methods.
例如,
@Cacheable
@Entity
public class User {
}
这篇关于如何在默认Spring Data JPA方法上添加QueryHints?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!