0
/**父實體**/延遲加載與QueryDsl /休眠不工作
@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);
}
******子實體******
@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;
}
當我試圖檢索父細節,它也獲取子記錄,這應該不會發生,因爲我提供了FetchType.LAZY。
*********** DAO類*******
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();
}
}
此外,我希望有條件(收費)取子記錄,我怎麼能實現這個?