2015-07-21 125 views
0

我有一個問題,這個查詢在JPA:JPA查詢右連接上

String query= "SELECT pc.pcKey, c.id, c.pcName 
    FROM Computer c RIGHT JOIN c.pcKey pc ON c.pcKey = pc.pcKey 
    WHERE pc.pcKey IS NOT NULL AND pc.pk.idLaboratory = :laboratoryId"; 

這是錯誤消息我得到:

with clause can only reference columns in the driving table [SELECT pc.pcKey, c.id, c.pcName FROM com.want.ecdlejb.hibernate.model.Computer c RIGHT JOIN c.pcKey pc ON c.pcKey = pc.pcKey WHERE pc.pcKey IS NOT NULL AND pc.pk.idLaboratory = :laboratoryId] 
at org.hibernate.hql.internal.ast.HqlSqlWalker$WithClauseVisitor.visit(HqlSqlWalker.java:508) 

實體計算機類

@ManyToOne 
@JoinColumn(name="pc_key", nullable=false) 
private PcKey pcKey; 

實體PcKey類

@OneToMany(mappedBy="pcKey") 
private Set<Computer> computerses; 

我讀到了這個錯誤的一些錯誤,但它是在2012年,我認爲他們已經修復它。任何人都知道如何正確地使這個查詢?

+1

「pc.pk.idLaboratory」 不明白。 – ozgur

+0

請你寫完整的實體。 – ozgur

+0

對不起應該是pc.idLaboratory – Faron

回答

2

嘗試JPQL查詢:

String query= " SELECT pcKey, c.id, c.pcName 
    FROM Computer c RIGHT JOIN Pckey pcKey 
    WHERE pcKey.id IS NOT NULL AND pcKey.idLaboratory = :laboratoryId";