kofhearts
kofhearts

Reputation: 3784

should the HQL query that is called of a specific domain be specific to that domain?

The grails documentation gives the following example for domain.executeQuery() method.

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

In another place, I have seen the following command.

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

It seems that the HQL query need not be specific to the domain class whose executeQuery() method we are calling. If so then it seems arbitrary and we can call executeQuery method of arbitrary domain class to execute arbitrary HQL queries. Please clear my misunderstanding if i have misunderstood the purpose of executeQuery(). Thanks!

Upvotes: 0

Views: 120

Answers (1)

Burt Beckwith
Burt Beckwith

Reputation: 75681

The class that you call executeQuery (and executeUpdate, withTransaction, withNewTransaction, withSession, withNewSession) on has no impact on how the methods run. The methods probably should have been added to a Gorm class but instead were added to all domain classes.

Upvotes: 2

Related Questions