我有這樣的家長:JPA - 只有獲得父母,而不是孩子
@Entity
@Table(name="parent")
public class Parent {
private List<Child> childs;
private List<AnotherChild> anotherChilds;
@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
public List<Child> getChilds() {
return childs;
}
@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
public List<AnotherChild> getAntoherChilds() {
return anotherChilds;
}
//Getters and Setters ommited
}
和兩個孩子這樣
@Entity
@Table(name="child")
public class Child {
private Parent parent;
@ManyToOne
@JoinColumn(name = "column_name")
public Parent getParent() {
return patern;
}
}
@Entity
@Table(name="another_child")
public class AnotherChild {
private Parent parent;
@ManyToOne
@JoinColumn(name = "column_name")
public Parent getParent() {
return patern;
}
}
我有一個名爲查詢它獲取所有的父母,但是這也正在加載所有的孩子?我怎樣才能阻止孩子自動加載?
謝謝。
請發佈您的查詢,獲取父。 –
@AbdullahWasi它只是標準的findAll查詢,並被稱爲表單JAX-RS作爲一個命名查詢 – iqueqiorio
延遲加載是默認的,所以如果他們被加載,那麼它是你的代碼,它是這樣做的 - 所以發佈相關碼。 –