Ich habe ein Elternteil wie folgt aus:JPA - Nur Eltern bekommen, keine Kinder
@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
}
und zwei Kinder mögen dieses
@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;
}
}
ich eine benannte Abfrage haben, die alle Eltern bekommt, aber das lädt auch alle Kinder? Wie kann ich die Kinder zum automatischen Laden anhalten?
Danke.
Bitte senden Sie Ihre Abfrage, die das übergeordnete Element abruft. –
@AbdullahWasi es ist nur die Standard-Abfrage findAll, und heißt Form JAX-RS als eine benannte Abfrage – iqueqiorio
Lazy Loading ist der Standard, also wenn sie geladen werden, dann ist es Ihr Code, dass es es tut - also die relevanten Code. –