Reputation: 123
I have a problem with this query in 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";
This is the error message I am getting:
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)
Entity Computer class
@ManyToOne
@JoinColumn(name="pc_key", nullable=false)
private PcKey pcKey;
Entity PcKey Class
@OneToMany(mappedBy="pcKey")
private Set<Computer> computerses;
I read about some bug with this error, but it was in 2012, i think they fix it already. Anyone know how to make this query correctly?
Upvotes: 0
Views: 1862
Reputation: 3466
Try JPQL query:
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";
Upvotes: 2