Grails/GORM where 子句如何设置 fetchMode 属性
在 Grails 2 中,我们都知道 where 子句创建 DetachedCriteria。此外,在创建普通 Criteria 查询时,还可以设置关系的 fetchMode 属性。但是,如果我要创建 where 子句查询,如何设置基础 Criteria 的 fetchMode 属性?
不起作用:
MyDomainClass.where {
foo == 'bar'
fetchMode "reference", FetchMode.EAGER
}
起作用,但使用旧的 Criteria 样式,而不是 where 子句:
MyDomainClass.withCriteria {
eq "foo", "bar"
fetchMode "reference", FetchMode.EAGER
}
请不要告诉我在域类映射中将获取模式设置为 eager。我知道这一点,并且需要在查询级别控制急切的获取。谢谢!
In Grails 2, we all know that a where clause creates a DetachedCriteria. Also, one can set the fetchMode property of a relationship when creating a normal Criteria query. But, if I'm creating a where-clause query, how do I set the fetchMode property of the underlying Criteria?
Does not work:
MyDomainClass.where {
foo == 'bar'
fetchMode "reference", FetchMode.EAGER
}
works, but uses old Criteria style, not where clause:
MyDomainClass.withCriteria {
eq "foo", "bar"
fetchMode "reference", FetchMode.EAGER
}
Please don't tell me to set the fetch mode to eager in the domain class mapping. I know about that, and need to control the eager fetching at the query level. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尚不支持此功能,因此请在 http://jira.grails.org/browse 创建功能请求/GRAILS
通过访问执行实际查询的 Hibernate
Criteria
实例,有一个有点黑客的解决方法:This isn't supported yet, so please create a feature request at http://jira.grails.org/browse/GRAILS
There is a somewhat hackish workaround though by accessing the Hibernate
Criteria
instance that does the actual querying: