gpt4 book ai didi

grails - 在Grails中执行executeQuery时如何访问关系表?

转载 作者:行者123 更新时间:2023-12-02 14:38:38 25 4
gpt4 key购买 nike

做HQL语句时可以访问关系表吗?

例如,我有3个表:account,commitment,account_commitment。它是使用以下域生成的:

class Account {
static hasMany = [ commits : Commitment ]

String name
}

class Commitment {
static hasMany = [ actors : Account ]

String description
}

我的最终和实际SQL查询是这样的:
SELECT 
b.id,
account_name,
d.nid,
d.title
FROM
account_commitment a, // is this available in HQL?
account b,
commitment c,
content_type_act d
where
d.nid = 3332
and a.account_id = b.id
and a.act_id = c.id
and c.act_id = d.nid

我相信HQL仅允许有效的类域。由于关系表是自动生成的,因此在HQL中可以吗?

谢谢。

最佳答案

不,HQL仅适用于映射的类。如果要运行SQL查询,只需使用groovy.sql.Sql。但是,如果您只想访问中间表以连接其他两个表,则这是不必要的,因为HQL已经知道表之间的关系。

关于grails - 在Grails中执行executeQuery时如何访问关系表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2699934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com