了解hibernate缓存
如果我在对象类中有这个方法:
@OneToMany( fetch = FetchType.EAGER,
cascade = { CascadeType.ALL },
mappedBy = "object" )
@org.hibernate.annotations.Cascade(
{org.hibernate.annotations.CascadeType.SAVE_UPDATE})
@Column( nullable = false )
public Set<ObjectEntry> getObjectEntries() {
return this.objectEntries;
}
并且我将 @cache
都放在 ObjectEntry
和 Object
上
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Object extends HashCodeValidator {
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class ObjectEntry extends HashCodeValidator
,我还需要将 @cache 放在getObjectEntries 像这样:
@org.hibernate.annotations.Cascade(
{org.hibernate.annotations.CascadeType.SAVE_UPDATE})
@Column( nullable = false )
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public Set<ObjectEntry> getObjectEntries() {
return this.objectEntries;
}
如果我专门添加,是否需要为每个查询定义缓存
hibernate.cache.use_query_cache = true
?
If I have this method in object class:
@OneToMany( fetch = FetchType.EAGER,
cascade = { CascadeType.ALL },
mappedBy = "object" )
@org.hibernate.annotations.Cascade(
{org.hibernate.annotations.CascadeType.SAVE_UPDATE})
@Column( nullable = false )
public Set<ObjectEntry> getObjectEntries() {
return this.objectEntries;
}
and I put @cache
both on ObjectEntry
and on Object
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Object extends HashCodeValidator {
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class ObjectEntry extends HashCodeValidator
Do I still need to put @cache on getObjectEntries like this:
@org.hibernate.annotations.Cascade(
{org.hibernate.annotations.CascadeType.SAVE_UPDATE})
@Column( nullable = false )
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public Set<ObjectEntry> getObjectEntries() {
return this.objectEntries;
}
Do I need to define cache for each query if I specifically add
hibernate.cache.use_query_cache = true
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,如果您愿意,您仍然必须缓存集合(它将缓存在特定的缓存区域中)。
如果我专门从有关
hibernate.cache.use_query_cache
属性的参考文档中 (第 3.4. 可选配置属性):所以,是的,您仍然需要设置一个查询可缓存(通过调用
setCacheable(true)
在查询或条件对象上)如果你愿意的话 - 在我看来这是一件好事。Yes, you still have to cache a collection if you want to (that will be cached in a specific cache region).
From the reference documentation about the
hibernate.cache.use_query_cache
property (section 3.4. Optional configuration properties):So, yes, you still have to set a query cachable (by calling
setCacheable(true)
on a query or criteria object) if you want to - which is IMO a good thing.