2013-04-07 156 views
1

我想將mysql代碼轉換成JPQL。我有兩張桌子。第一個表名爲Product。它具有以下字段:id和代碼。第二個表稱爲Descriptor,它具有3個字段:id(來自產品表),code(來自產品表)和Description是特定於Descriptor表的字段。我想加入這些表格,因此對於產品ID和產品代碼的每個唯一組合,我想要添加說明。JPQL內部連接

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; 

所有的意見非常歡迎感謝

回答

0

閱讀documentation about HQL。加入,在HQL,使用實體之間的關聯進行:

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

(假設產品和描述符之間的OneToOne協會,利用各自的ID)。

+0

我讀過文檔。這很糟糕。儘管感謝您的反饋。我很感激你花時間回答 – user2225631 2013-04-07 16:52:20