HQL加入Grails [英] HQL joins in Grails

查看:80
本文介绍了HQL加入Grails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的关系

I have a relationship like this

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

I have an instance of Thing. I want to get all instances of Bar that are associated with all instances of Foo that are associated with the instance of Thing that I have.

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

I have used Grails executeQuery method several times but my query does not work.

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

Here is a working query that will get all instance of Foo related to an instance of Bar. I expect the query I need will look very similar, I'm just having trouble with the HQL joins.

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


推荐答案

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。

grails should support setting parameters and you basically need to pass the array of ids to the query.. The final part of the query should evaluate to (1,2,3,4) where 1,2,3,4 are the ids of the valid things.

这篇关于HQL加入Grails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆