【发布时间】:2017-04-30 13:59:02
【问题描述】:
我有这样的父母:
@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 作为命名查询
-
延迟加载是默认设置,因此如果正在加载它们,那么它正在执行的是您的代码 - 所以发布相关代码。
-
你有没有为这个没有孩子的抓取父母找到任何解决方案?
标签: java sql spring hibernate jpa