我有下一堂课关系:
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的公司?
答案 0 :(得分:1)
List<Company> list = session.createQuery("from Company company where company.companySecUsers.isRead=:isRead").setParameter("isRead",1).list();
答案 1 :(得分:1)
select company from Company company
join company.companySecUsers user
where user.id = <ID> and user.isRead = 1