【发布时间】:2019-01-02 06:50:01
【问题描述】:
public class MyClass{
@Id
@Column(name = "id", nullable = false)
Long id;
private AnotherClass anotherClass;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "another_id")
@Cacheable(value = "getAnotherClass", unless = "#result == null", key = "#id")
public AnotherClass getAnotherClass(){
return anotherClass;
}
}
public class AnotherClass{
@Id
@Column(name = "id", nullable = false)
Long id;
}
有 2 个班级。 MyClass 包含 AnotherClass 的外键。
我需要使用AnotherClass 的id 缓存getAnotherClass。
怎么做?
【问题讨论】:
-
spring.io/guides/gs/caching这个方法你试过吗?
-
使用
@Cacheable(value = "getAnotherClass")仍然会导致大量实际的数据库调用。
标签: java ehcache spring-cache