したがって、従業員に制限を設ける場合は、
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>);