在Grails GORM查询中使用连接 [英] The use of join in Grails GORM queries

查看:172
本文介绍了在Grails GORM查询中使用连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Grails中,我们定义域类的方式明确指出域类之间的关系,如一对多或belongsTo(如果有的话)。由于Grails基于DRY,这是否意味着我们在Grails的DomainClass.ExecuteQuery方法中执行复杂的HQL查询时无需使用join关键字?

解决方案

Grails不会改变您编写HQL的方式无论您使用Grails域类还是POJO,它都是一样的。如果您需要编写查询来导航对象图,那么您需要使用与使用HQL相同的语法,如 FROM parent p JOIN p.child c WHERE c.age = 10 。 Criteria查询以相同的方式工作,但您只需要使用闭包。



查看 documentation (第5.4.3节)以获取更多信息。


In Grails we define domain classes in such a way that clearly indicates the relationship between domain classes such as one to many or belongsTo (if any). Since Grails is based on DRY, does that mean we do not need to use the join keyword when performing complex HQL queries in Grails DomainClass.ExecuteQuery method?

解决方案

Grails doesn't change the way you write your HQL it is the same whether your using Grails domain classes or POJO's. If you need to write queries that navigate the object graph then you need to use the same syntax as you would with HQL like FROM parent p JOIN p.child c WHERE c.age = 10. Criteria queries work in the same way but you just get to use closures.

Take a look at the documentation (section 5.4.3) for more information.

这篇关于在Grails GORM查询中使用连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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