【发布时间】:2012-08-02 01:00:35
【问题描述】:
因此,如果我要为员工设置限制,我会说
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>);
【问题讨论】: