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

发布于 2024-08-30 12:51:46 字数 677 浏览 1 评论 0原文

执行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中可以吗?

谢谢。

Is it possible to access the relationship table when doing HQL statement?

As an example, I have 3 tables: account, commitment, account_commitment. It was generated using these domains:

class Account {
   static hasMany = [ commits : Commitment ]

   String name
} 

class Commitment {
   static hasMany = [ actors : Account ]

   String description
}

My final and actual SQL query is something like this:

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

I believe HQL only allows valid class domains. Since the relationship table is automatically generated, is this possible in HQL?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪花飘飘的天空 2024-09-06 12:51:46

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

No, HQL only works with mapped classes. If you want to run SQL queries just use groovy.sql.Sql. But if you only want to access the intermediate table to join the other two, that's unnecessary since HQL knows about the relationships between tables already.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文