1

我有下一个班级关系:

public class Company {
  . . .
  @OneToMany(mappedBy = "company", fetch = FetchType.EAGER, cascade=CascadeType.PERSIST)
  private Set<CompanySecUser> companySecUsers;
  . . .
}
public class CompanySecUser{
    . . .
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="USER_ID")
    private User secUser;

    @Column(name = "IS_READ")
    private BigDecimal isRead;
    . . .
}

现在如何在公司实体的 JPA 中编写查询以仅获取具有指定 secUser.id 和 isRead = 1 的公司?

4

2 回答 2

1
List<Company> list = session.createQuery("from Company company where company.companySecUsers.isRead=:isRead").setParameter("isRead",1).list();
于 2013-09-30T14:36:11.783 回答
1
select company from Company company 
    join company.companySecUsers user 
    where user.id = <ID> and user.isRead = 1
于 2013-09-30T14:47:22.067 回答