我正在使用Hibernate 4.3.6.Final
我有3个班级:
你可以想象,父母有很多孩子,孩子有很多孙子。
class Parent {
@OneToMany(orphanRemoval = true)
@OrderColumn(name = "list_order")
@JoinColumn(name = "parent_id", nullable = false)
@Cascade(value = CascadeType.ALL)
private List<Child> children = new ArrayList<>();
}
class Child {
@ManyToOne(optional = false)
@JoinColumn(name = "parent_id", insertable=false, updatable=false, nullable = false,
foreignKey = @ForeignKey(name = "fk_child_parent_id"))
private Parent parent;
@OneToMany(orphanRemoval = true, fetch = FetchType.EAGER)
@OrderColumn(name = "list_order")
@JoinColumn(name = "child_id", nullable = false)
@Cascade(value = CascadeType.ALL)
private List<Grandchild> grandchildren = new ArrayList<>();
}
class Grandchild {
@ManyToOne(optional = false)
@JoinColumn(name = "child_id", insertable=false, updatable=false, nullable = false,
foreignKey = @ForeignKey(name = "fk_grandchild_child_id"))
private Child child;
}
我想懒洋洋地装载儿童,但EAGER在装载儿童时装载孙子。
这意味着:
我已将EAGER设置为Child&lt; - &gt; Granchild关联,但它没有效果:当我调用parent.getChildren()时,只提取子项,而不是孙子。
感谢您的帮助!
更新@Zeus,在我的数据库中: