我有这样的家长: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
延迟加载是默认的,所以如果他们被加载,那么它是你的代码,它是这样做的 - 所以发布相关码。 –