开发者

How to access relationship table when doing executeQuery in Grails?

开发者 https://www.devze.com 2022-12-28 03:22 出处:网络
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:

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消