Livin As
Livin As

Reputation: 143

Hibernate Criteria join query

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

Answers (2)

Vishnu
Vishnu

Reputation: 4263

Try this

Criteria criteria = sessionFactory.getCurrentSession()
                                  .createCriteria(Employee.class)
                                  .createAlias("meetings", "m", JoinType.LEFT_OUTER_JOIN)

Upvotes: 2

jose
jose

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

Related Questions