Organizational Research By

Surprising Reserch Topic

how to retrieve a complex class and its members using hibernate projection


how to retrieve a complex class and its members using hibernate projection  using -'java,sql,hibernate,orm,hibernate-criteria'

I have a class as following that need to retrieve from DB using Hibernate.
The problem is my class has multiple members and majority of them are classes, how can I retrieve them?

@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);
   ..

}


I need to retrieve student id 1 and all its courses, its dealer and  list of dealers' cars.

My projection is as following but it does not return anything.

  ...
    .setProjection(Projections.projectionList()

    .add(Projections.property("friends.cars").as("cars")
    ...

    
asked Oct 7, 2015 by mannumits1
0 votes
6 views



Related Hot Questions



Government Jobs Opening


...