根实体及其集合的不同缓存并发策略(Hibernate 与 EHCache)?
给出的示例来自 Hibernate docs 并修改它,以便根级实体(客户)是只读的,而其集合之一(票证)是读写的:
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class Customer {
...
@OneToMany(...)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public SortedSet<Ticket> getTickets() {
return tickets;
}
...
}
从缓存访问客户时,票证集合会刷新吗?
Given example from Hibernate docs and modifying it so that root level entity (Customer) is read-only while one of its collections (tickets) is read-write:
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class Customer {
...
@OneToMany(...)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public SortedSet<Ticket> getTickets() {
return tickets;
}
...
}
Would collection of tickets get refreshed when accessing customer from cache?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在其他地方修改给定
客户
的一张票据
,是的。你为什么不测试一下这个?我们假设Cutomer#1
在其tickets
集合中具有Ticket#1
和Ticket#2
。我运行了这段代码:这表明票证集合被“刷新”。
If you modify one of the
tickets
of a givenCustomer
somewhere else, yes. Why don't you test this? Let's assumeCutomer#1
hasTicket#1
andTicket#2
in itstickets
collection. I ran this code:Which shows the collection of tickets gets "refreshed".