grailshqldomain-object

Does it matter what Domain Object you execute a query on in grails


Does it matter what domain object you use when you execute a query? For instance, I have these two domain objects

Class A {
    String name
}

Class B {
    String name
}

If I want to get all A objects, I can do the following

A.executeQuery('FROM A')

But I can also call the same query from a different domain object and get the exact same results as so

B.executeQuery('FROM A')

Is there a difference between these two statements performance wise? Maybe something under the hood that is happening differently?

For a little more context, I am writing a service where the application will be executing queries off of domain objects dynamically. So I could either pick a base domain object and just execute off that every time, or I can maybe make an instance of the domain object with a string that is provided into the method.

Thanks


Solution

  • No, it does not matter. In this case it's just executing HQL (hibernate query) and either domain class acts exactly the same in this respect for executeQuery.

    In your specific case I'd just use a single domain class to execute all the queries from. No need to change the type.