我有父->子双向关系如下...
class Parent{
@OneToMany(mappedBy="parent", fetch = FetchType.EAGER)
Collection<Child> children;
}
class Child{
@ManyToOne
@JoinColumn(name="PARENT_ID")
private Parent parent;
}
当我明确删除子项,然后加载其父项(包含所有子项)时,我会在父项的子项集合中获得先前删除的子项... JPA 提供程序是休眠...
Child child= childRepo.findOne(CHILD_ID);
childRepo.delete(child);
childRepo.flush();
// next, returns collection without deleted child
Collection<Child> children= childRepo.findAll();
Parent parent = parentRepo.findById(PARENT_ID);
/// next, returns collection including deleted child
Collection<Child> parentChildren = parent.getChildren();
我不明白这是什么问题?每个 find* 方法都执行 select(在列表中,这些 SELECT 记录在控制台中),但它们返回不同的结果......