我有一個類,如下需要使用Hibernate從數據庫中檢索。 問題是我的課有多個成員,他們中的大多數都是班級,我如何檢索他們?如何使用Hibernate Projection檢索複雜的類及其成員?
@Entity
public class Student {
@Id
long id;
String name;
String fname;
@OneToMany
List<Course> courses;
@ManyToOne
Dealer dealer;
...
}
@Entity
public class Dealer {
@Id
long id;
String name;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "cr.dealer", cascade = CascadeType.ALL)
Set<Car> cars = new HashSet<Cars>(0);
..
}
我需要檢索學生id 1及其所有課程,其經銷商和經銷商的汽車列表。
我的預測如下,但它不返回任何內容。
...
.setProjection(Projections.projectionList()
.add(Projections.property("friends.cars").as("cars")
...
感謝您的回答,請你看看我的問題在http://stackoverflow.com/questions/29980421/how-to-retireve-a-set-member-objects-using-hibernate – Jack