Hibernate Criteria join query
12,535
Solution 1
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")));
Solution 2
Try this
Criteria criteria = sessionFactory.getCurrentSession()
.createCriteria(Employee.class)
.createAlias("meetings", "m", JoinType.LEFT_OUTER_JOIN)
Author by
Livin As
Updated on August 29, 2022Comments
-
Livin As almost 2 years
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?
-
gran_profaci about 11 yearsDo we have to specify an all new .hbm.xml model for the return statement from this query?