我有两个表:客户和命令,这是@OneToMany
从客户端到命令的关系,一个客户端有很多命令。表命令包含 : idCommand, date, nameCommande, idCustomer
。表客户包含:idCustomer, nameClient, email
。所有 JPA 和 EJB 都已设置好,我可以使用托管 bean 中的 HQL 查询轻松获取命令或客户端列表,并使用此代码在 JSP 中列出它们。
public List<Commande> selectAllCommandes() {
List<Commande> commandes = em.createQuery("select c from Commande c").getResultList();
return commandes;
}
public List<Customer> selectAllCustomers() {
List<Customer> customers = em.createQuery("select cu from Customer cu").getResultList();
return customers;
}
如何idCustomer
以显示客户名称而不是其 ID 的方式将两个表与列连接起来?我用过这个 HQL 查询
SELECT c.date, c.name Commande, cu.nameClient FROM Commande AS c, Customer AS cu WHERE cu.idCustomer = c.idCustomer
但我不知道List<>
我需要使用哪种类型来获得结果/