HQL加入Grails

时间:2012-06-20 04:22:15

标签: grails join groovy hql

我有这样的关系

class Foo {
    static hasMany = [bars: Bar, things: Thing]
}

class Bar {
    // Has nothing to tie it back to Foo or anything else of importance
}

class Thing {
    // Has nothing to tie it back to Foo or anything else of importance
}

我有一个Thing的实例。 我希望获得与Bar的所有Foo实例关联的Thing的所有实例,这些实例与我拥有的executeQuery实例相关联。

我多次使用Grails Foo方法,但我的查询不起作用。

这是一个有效的查询,它将获取与Bar实例相关的SELECT DISTINCT f FROM Foo f INNER JOIN f.bars bars WHERE bars =:bars 的所有实例。我希望我需要的查询看起来非常相似,我只是遇到了HQL连接问题。

{{1}}

1 个答案:

答案 0 :(得分:3)

SELECT DISTINCT f.Bars FROM Foo f inner join f.things thing where thing.Id in (:validThingIds)

grails应该支持设置参数,你基本上需要将id数组传递给查询..查询的最后部分应该计算为(1,2,3,4),其中1,2,3,4是ids的id有效的东西。