调用特定域的HQL查询是否应该特定于该域?

时间:2015-08-31 07:18:28

标签: grails hql

grails文档为domain.executeQuery()方法提供了以下示例。

  Account.executeQuery("select distinct a.number from Account a")

在另一个地方,我看到了以下命令。

Registration.executeQuery(
            'select i.id from SaleInvoice i '
            + 'left join i.entries ie '
            + 'left join ie.discount d '
            + 'left join d.discountCode dc '
            );

似乎HQL查询不一定特定于我们调用其executeQuery()方法的域类。如果是这样,那么它似乎是随意的,我们可以调用任意域类的executeQuery方法来执行任意的HQL查询。如果我误解了executeQuery()的目的,请清除我的误解。谢谢!

1 个答案:

答案 0 :(得分:1)

您致电executeQuery(以及executeUpdatewithTransactionwithNewTransactionwithSessionwithNewSession)的课程对您没有影响方法如何运行。这些方法可能应该已添加到Gorm类中,而是添加到所有域类中。