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();
}
}
此外,我希望有条件(收费)取子记录,我怎么能实现这个?