2011-09-12 143 views
0

我總是得到錯誤列太多當我執行此查詢。HQL子查詢的查詢選擇

SELECT o FROM Overlay o WHERE (:coordinate) IN ELEMENTS(o.blocksCoordinates) 

如果我在SQL做它的工作原理:

Select * from Overlay overlay0_ where (0,0) in (select x, y from ... 

座標是用x和y的值一個簡單的嵌入式實體。

@ElementCollection 
private Set<Coordinate> blocksCoordinates = new HashSet<Coordinate>(); 

我的座標實體:

@Embeddable 
public class Coordinate implements Serializable { 
    private static final long serialVersionUID = -5866341829302555966L; 

    protected int x; 
    protected int y; 

我在做什麼錯?

回答

1

試試倒過來:

select o from Overlay o left outer join o.blocksCoordinates as c where c = :coordinate 

或者使用with關鍵字:

select o from Overlay o join o.blocksCoordinates as c with c = :coordinate 

使用該查詢應返回其C上的加入任何覆蓋=座標成功。

編輯:或者,嘗試使用x和y的值:

select o from Overlay o join o.blocksCoordinates as c with c.x = :x and c.y = :y 
+0

沒有工作。 :-(同樣的錯誤:org.hibernate.HibernateException:所致。SqlNode的文字並沒有提及列 – mkuff

+0

的預期數量也許Embedded不適合此查詢 – mkuff

+0

x和y的最後解決辦法工作得很好非常感謝! ;-) – mkuff