我有三个实体'A','B','C':
@Entity
public class A implements Serializable {
...
private B b;
@OneToOne(mappedBy = "a", fetch = FetchType.LAZY)
@Cascade({CascadeType.ALL})
public B getB() {
return b;
}
public void setB(B b) {
this.b = b;
}
...
}
@Entity
public class B implements Serializable {
...
private A a;
@OneToOne(fetch = FetchType.LAZY)
public A getA() {
return a;
}
public void setA(A a) {
this.a = a;
}
...
private Collection<C> cCollection;
@OneToMany(mappedBy = "b", fetch = FetchType.LAZY)
public Collection<C> getCCollection() {
return cCollection;
}
public void setCCollection(Collection<C> cCollection) {
this.cCollection = cCollection;
}
...
}
@Entity
public class C implements Serializable {
...
private B b;
@ManyToOne(optional = false, fetch = FetchType.LAZY )
public B getB() {
return b;
}
public void setB(B b) {
this.b= b;
}
}
当我更新 B.cCollection - 添加或删除 C 对象 - 然后刷新对象 a 时,我预计这些更改会影响 a.getB().getCCollection() 的结果,但它永远不会发生并且 cCollection 列表不会被更新. 我对 refresh() 操作有误吗?
//Adding or removal C objects to/from a.getB().getCCollection()
//Persisting changes
myEM.refresh(a);
(注意:我使用的是hibernate和JPA 2.0。在数据库中持久化数据没有问题,并且确实有效)。