找不到方法 - findOrCreateWhere - gorm

时间:2012-01-29 23:42:28

标签: grails groovy gorm

我创建了一个只包含一个变量权限的Role类:

class Role {
    String authority
}

现在,当我尝试在BootStrap.groovy(grails app)中保存新值时,我这样做:

def adminRole = Role.findOrCreateWhere(authority: "ROLE_ADMIN");

当我运行时,我遇到以下异常:

2012-01-29 23:35:03,067 [Thread-9] ERROR org.codehaus.groovy.grails.web.context.GrailsContextLoader  - Error executing bootstraps: groovy.lang.MissingMethodException: No signature of method: org.rango.auth.Role.findOrCreateWhere() is applicable for argument types: () values: []
Possible solutions: findOrCreateWhere(java.util.Map), findOrSaveWhere(java.util.Map)
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: org.rango.auth.Role.findOrCreateWhere() is applicable for argument types: () values: []
Possible solutions: findOrCreateWhere(java.util.Map), findOrSaveWhere(java.util.Map)
    at grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.java:290)
    at grails.util.Environment.executeForEnvironment(Environment.java:283)
    at grails.util.Environment.executeForCurrentEnvironment(Environment.java:259)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: groovy.lang.MissingMethodException: No signature of method: org.rango.auth.Role.findOrCreateWhere() is applicable for argument types: () values: []
Possible solutions: findOrCreateWhere(java.util.Map), findOrSaveWhere(java.util.Map)
    at BootStrap$_closure1.doCall(BootStrap.groovy:16)
    ... 8 more

我的代码出了什么问题?

谢谢!

1 个答案:

答案 0 :(得分:-1)

试试这个:def adminRole = Role.findOrCreateWhere([authority:“ROLE_ADMIN”]);