如何从以下 sql 创建 Hibernate 条件查询?
String hql = "select e.employeeId,m.meetingId,e.firstname from Employee e join e.meetings m";
谁能提供相应的条件查询?
条件查询是:
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")));
试试这个
Criteria criteria = sessionFactory.getCurrentSession()
.createCriteria(Employee.class)
.createAlias("meetings", "m", JoinType.LEFT_OUTER_JOIN)