I want a grails service to be able to access Domain static methods, for queries, etc.
For example, in a controller, I can call
IncomingCall.count()
to get the number of records in table "IncomingCall"
but if I try to do this from inside a service, I get the error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'incomingStatusService': Invocation of init method failed; nested exception is groovy.lang.MissingMethodException: No signature of method: static ms.wdw.tropocontrol.IncomingCall.count() is applicable for argument types: () values: []
How do these methods get injected? There's no magic def statement in a controller that appears to do this. Or is the problem that Hibernate isn't available from my Service class?
I also tried it this way:
import ms.wdw.tropocontrol.IncomingCall
import org.codehaus.groovy.grails.commons.ApplicationHolder
// ...
void afterPropertiesSet() {
def count = ApplicationHolder.application.getClassForName("IncomingCall").count()
print "Count is " + count
}
and it failed. ApplicationHolder.application.getClassForName("IncomingCall") returned null. Is this just too early to call this? Is there a "late init" that can be called? I thought that was the purpose of "afterPropertiesSet()"...