/** Mutter Entity **/Lazy Loading-mit QueryDsl/Hibernate funktioniert nicht
@Entity
@Table(name = "Parent")
public class Parent {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "parentId", unique = true, nullable = false)
private Integer parentId;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "parent")
@JsonManagedReference
private Set<Child> childs = new HashSet<Child>(0);
}
****** Das Kind Entity ******
@Entity
@Table(name = "Child")
public class Child {
private static final long serialVersionUID = 1L;
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Parent.class)
@JoinColumn(name = "GuestID")
@JsonBackReference
private Parent parent;
}
Wenn Ich habe versucht, übergeordnete Details abzurufen, es auch Kind-Datensatz abrufen, was nicht passieren sollte, da ich FetchType.LAZY bereitgestellt habe.
*********** DAO Klasse *******
public class ParentRepositoryImpl implements ParentRepository {
public final List<Parent> retrieveParentList(){
QParent qParent = QParent.parent;
JPQLQuery<Parent> query = new JPAQuery<Parent>(em);
List<Parent> parents = query.from(qParent).fetch();
}
}
i bedingt Kind Rekord holen (auf Anfrage) auch wollen, wie kann ich erreichen Dies?