【发布时间】:2014-06-24 09:49:29
【问题描述】:
我正在使用 grails 2.2.4 并想编写可能生成 SQL 的标准:
select r.value from group g, rating r where r.groupId = g.id and g.name = ?
如果我们具有以下域结构:
class Group {
String name
}
class Rating {
Long groupId
int value
}
如何使用 grails 标准编写此内容?
我写的是这样的:
def result = Rating.withCriteria {
projections {
property("value")
}
eq "groupId", new DetachedCriteria(Group).build {
projections {
property("id")
}
eq("name", "Group A")
}
}
但是由此,hibernate 正在生成子查询。有什么猜测吗?
【问题讨论】:
-
是否有理由将其建模为 id 的 Long 属性而不是普通的多对一关联 (
Group group)?它将提供相同的表结构,但您可以以正常方式查询关联。
标签: grails