hibernate配置了二级缓存和查询缓存,在查询Problem实体时走缓存,但是getAnswers()时却不走缓存(能输出hql语句),也许有配置的地方 也许没有
请熟悉缓存配置的帮忙
[code="java"]@Entity
@Table(name="ask_problem")
@Searchable(alias = "problem")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Problem implements Serializable{
//省略属性和getter setter
@OneToMany(mappedBy="problem", cascade = { CascadeType.REMOVE })
@OrderBy("right DESC, answerTime ASC")
public Set<Answer> getAnswers() {
return answers;
}
public void setAnswers(Set<Answer> answers) {
this.answers = answers;
}
}[/code]
[b]问题补充:[/b]
这个问题已经找到答案 如下配置
[code="java"]@OneToMany(mappedBy="problem", cascade = { CascadeType.REMOVE })
@OrderBy("right DESC, answerTime ASC")
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) //添加这句就ok了
public Set getAnswers() {
return answers;
}[/code]