【问题标题】:HQL joins in GrailsHQL 加入 Grails
【发布时间】:2012-06-20 04:22:15
【问题描述】:

我有这样的关系

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 的实例。 我想获取与我拥有的Thing 实例相关联的所有Foo 实例相关联的Bar 实例。

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

这是一个有效的查询,它将获取与Bar 实例相关的所有Foo 实例。我希望我需要的查询看起来非常相似,我只是遇到了 HQL 连接问题。

SELECT DISTINCT f FROM Foo f INNER JOIN f.bars bars WHERE bars =:bars

【问题讨论】:

    标签: grails join groovy hql


    【解决方案1】:
    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 是有效事物的 id .

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-10
    • 2016-11-23
    • 1970-01-01
    相关资源
    最近更新 更多