2

したがって、従業員に制限を設ける場合は、

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>);
4

2 に答える 2

0

これを試しましたか?

     Criteria crit = sess.createCriteria(Employee.class, "employee");
     crit.add(Restrictions.in("employee", employees));
于 2012-08-05T17:21:43.077 に答える