HQL子查询查询选择

时间:2011-09-12 13:51:09

标签: java sql hibernate 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 ...

Coordinate是一个带有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 个答案:

答案 0 :(得分: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