[英]Hibernate 2nd Level Cache: Update cached collection on creating of entity in oneToMany relation
我有以下 class
@Entity(name = "table")
@Table(name = "table")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SomeClass {
@Id
long id;
@OneToMany(mappedBy = "someObject")
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
private List<AnotherClass> anotherObjects;
}
還有另一個 class:
public class AnotherClass{
@Id
long id;
@ManyToOne
@JoinColumn(name = "some_coulmn")
SomeClass someObject;
}
The scenario is that when I create an object from type AnotherClass
assigning it a certain someClass
object and then retrieve that someClass
object, I do not see the newly created object (unless I flush the cache and restart).
每當將新實體添加到該關系中時,我能做些什么來更新表示兩個實體之間關系的集合嗎?
注意:我在 Spring 啟動 2.1.8 項目中使用 hibernate 5.3。
當您有雙向關系時,我認為通常建議更新兩端。 在您的情況下,當創建 AnotherClass 的實例並將其鏈接到 SomeClass 的實例時,您還應該將 AnotherClass 添加到相應的 anotherObjects 列表中。
你會在這個問題中找到更詳細的解釋
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.