我有一个非常简单的问题 - 我无法在google上找到解决方案:)
我有公司和子类客户电话
public class Company {
private Long id;
private String companyName;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "companyID")
private Set<Client> clients;
setters .. getters
}
如何在不获得整个公司课程并编写类似内容的情况下获得客户数量:
public Company getClientsCount(Long companyID) {
Query q = em.createQuery("SELECT c FROM Company c where c.id =:companyID");
q.setParameter("companyID", companyID);
return (Company) q.getSingleResult();
}
之后:
int count = company.getCleints().size;
提前致谢