1

我正在尝试将 mysql 代码转换为 JPQL。我有两张桌子。第一个表名为 Product。它有以下字段:id 和 code。第二个表称为描述符,它有 3 个字段:id(来自产品表)、代码(来自产品表)和描述,它是描述符表的特定字段。我想加入表格,因此对于产品 ID 和产品代码的每个唯一组合,我都希望添加描述。

    The Sql is as follows ( this is correct): 
    Select Product.id, Product.code, Descriptor.DESCRIPTION
    from Product Inner join Descriptor where 
    Product.id = Descriptor.id and 
    Product.code = Descriptor.code

(The error is in here)
The JPQL I am trying is as follows which results in a "path" error
select p from Product p INNER JOIN Descriptor d where 
p.id = d.id and p.code = d.code;

非常欢迎所有建议谢谢

4

1 回答 1

0

阅读有关 HQL 的文档。在 HQL 中,连接是使用实体之间的关联完成的:

select p from Product p 
inner join p.descriptor d 
where p.code = d.code;

(假设 Product 和 Descriptor 之间存在 OneToOne 关联,使用它们各自的 ID)。

于 2013-04-07T16:49:42.000 回答