Reputation: 143
How do I create a Hibernate criteria query from the following sql?
String hql = "select e.employeeId,m.meetingId,e.firstname from Employee e join e.meetings m";
Can anyone please provide the corresponding criteria query?
Upvotes: 3
Views: 12634
Reputation: 4263
Try this
Criteria criteria = sessionFactory.getCurrentSession()
.createCriteria(Employee.class)
.createAlias("meetings", "m", JoinType.LEFT_OUTER_JOIN)
Upvotes: 2
Reputation: 144
the criteria query is:
Criteria c = session.createCriteria(Employee.class, "e");
c.createAlias("e.meetings", "m"); // inner join by default
c.setProjection( Projections.distinct( Projections.projectionList()
.add( Projections.property("e.employeeId"), "employeeId")
.add( Projections.property("m.meetingId"), "meetingId")
.add( Projections.property("e.firstname"), "firstname")));
Upvotes: 6