How to add QueryHints on Default Spring Data JPA M

2019-03-13 07:47发布

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); }

However, how to add @QueryHints on existing parent methods like findAll()?

Thanks.

2条回答
\"骚年 ilove
2楼-- · 2019-03-13 08:21

Originally, there was no support for query hint annotations in default CRUD methods, but apparently it hass been fixed for version 1.6M1:

https://jira.spring.io/browse/DATAJPA-173

查看更多
爷的心禁止访问
3楼-- · 2019-03-13 08:25

findAll(), findOne() etc. are not Query(s). Any caching specifications on the entity take effect in these methods.

For example,

@Cacheable
@Entity
public class User {

}
查看更多
登录 后发表回答