gpt4 book ai didi

java - 了解hibernate缓存

转载 作者:行者123 更新时间:2023-12-02 06:15:38 25 4
gpt4 key购买 nike

如果我在对象类中有这个方法:

@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同时放在ObjectEntryObject

@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

最佳答案

(...) Do I still need to put @cache on getObjectEntries like this:

是的,如果您愿意,您仍然需要缓存集合(这将缓存在特定的缓存区域中)。

Do I need to define cache for each query if I specifically add hibernate.cache.use_query_cache = true

来自有关 hibernate.cache.use_query_cache 属性的引用文档(3.4. Optional configuration properties 部分):

Enables the query cache. Individual queries still have to be set cachable. e.g. true|false

所以,是的,如果您愿意,您仍然需要设置一个查询可缓存(通过在查询或条件对象上调用setCacheable(true)) - 这是在我看来,这是一件好事。

关于java - 了解hibernate缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3187397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com