3

如何从以下 sql 创建 Hibernate 条件查询?

String hql = "select e.employeeId,m.meetingId,e.firstname from Employee e join e.meetings m";

谁能提供相应的条件查询?

4

2 回答 2

6

条件查询是:

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")));
于 2012-10-09T09:37:56.600 回答
2

试试这个

Criteria criteria = sessionFactory.getCurrentSession()
                                  .createCriteria(Employee.class)
                                  .createAlias("meetings", "m", JoinType.LEFT_OUTER_JOIN)
于 2013-06-27T07:33:25.723 回答