我有隔壁类(class)的关系:
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 中对 Company 实体编写查询以仅获取具有指定 secUser.id 且 isRead = 1 的公司?
最佳答案
select company from Company company
join company.companySecUsers user
where user.id = <ID> and user.isRead = 1
关于java - JPA 查询集合中的 bean 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19096848/