因此,如果我要对员工进行限制,我会说
Criteria crit = sess.createCriteria(Employee.class);
所以现在我试图弄清楚是否有可能而不是这样做:
List<String> employeeIds;
Criteria crit = sess.createCriteria(Employee.class);
crit.add(Restrictions.in("id", employeeIds));
crit.createAlias("car", "car");
return crit.list();
去做这个:
List<Employee> employees;
Criteria crit = sess.createCriteria(Employee.class);
crit.add(Restrictions.in("", employees)); //Doesn't work, but I think you get what I'm trying to do, query by objects themselves
crit.createAlias("car", "car");
return crit.list();
我试图通过员工对象列表限制对员工的查询。稍后我与另一个表进行连接,因此通过我正在为其创建条件的类的特定实例列表进行限制是很有用的。
这将与此示例 SQL 相同
SELECT * FROM employees
JOIN cars
ON cars.ownerName like employees.name
WHERE employees.id in
(<list of employee ids goes here>);