1
votes

Trying to run the following command in grails console:

Family.where() {password =~ "%qw%"}

A very simple query on a stored object. I'm getting back:

    ERROR groovy.lang.MissingMethodException:
No signature of method: com.babyboom.Family.where() is applicable for argument types: (groovysh_evaluate$_run_closure1) values: [groovysh_evaluate$_run_closure1@34356294]
Possible solutions: where(groovy.lang.Closure), merge(), every(), grep(), merge(com.babyboom.Family), merge(java.util.Map)

I understand that the closure I created is a different than the expected one. Couple of questions:

1
Is com.babyboom.Family a domain class? - Jeff Scott Brown
"Why there are 2 types of closures ?" - There aren't 2 types of closures. I don't know why you think there are and I don't know what you mean by "I understand that the closure I created is a different than the expected one." - Jeff Scott Brown
"It works well when using GroovyConsole" - In order for that to query to work in the groovy console you would have to have somehow bootstrapped the Grails environment in that console which would take quite a bit of work. Is that what you did? - Jeff Scott Brown
Is com.babyboom.Family a domain class? - Yes - Efi MK
When running grails console from my project directory everything gets bootstrap for me - Efi MK

1 Answers

0
votes

This is likely a classloader bug with the grails shell. To reproduce, add dependency to BuildConfig.gradle:

runtime "org.grails:grails-datastore-simple:3.1.2.RELEASE"

then run

import org.grails.datastore.mapping.simple.SimpleMapDatastore
import org.grails.datastore.gorm.GormStaticApi
class Bar {}

class Foo extends GormStaticApi<Bar> {
    Foo() {
        super(Bar, new SimpleMapDatastore(), [], null)
    }
}

def f = new Foo()

In grails console yields:

Result: Foo@699c0395

In grails shell yields:

groovy:000> def f = new Foo()
ERROR java.lang.LinkageError:
loader constraint violation: when resolving overridden method "Foo.$getStaticMetaClass()Lgroovy/lang/MetaClass;" the class loader (instance of groovy/lang/GroovyClassLoader$InnerLoader) of the current class, Foo, and its superclass loader (instance of org/codehaus/groovy/grails/cli/support/GrailsRootLoader), have different Class objects for the type ()Lgroovy/lang/MetaClass; used in the signature