-1

我该如何编写这个 jpa/hibernate sql 语句(如果可能的话)

我有 2 个实体

@Entity
public class Employees    
  @OneToMany(cascade=CascadeType.ALL)
  private List<Benefits> benefits;

========================================

@Entity    
public class Benefits
  private String department

我需要检索您的福利列表中包含在某些部门列表中的员工列表。

我写了以下 JPA/Hibernate sql 语句,

from Employees e where e.benefits exists ( from Benefits b where b.department in (?1) )", someListOfDepartments )

但它会引发异常。可以做这样的查询吗?

4

1 回答 1

0

总部:

from Employees e INNER JOIN e.benefits b where b.department in (:depts)

标准:

session.createCriteria(Employees.class);
    criteria3.createAlias("benefits", "b",
            CriteriaSpecification.INNER_JOIN)
            .setFetchMode("b", FetchMode.JOIN)
    .add(Restrictions.in("b.department", depts));
于 2012-11-21T13:39:19.610 回答