Grails 2.2.2 createCriteria抛出错误

时间:2014-06-11 10:13:51

标签: grails groovy

我查看了互联网,但除了Jira Issue我使用 Grails 2.2.2 之外没有发现任何问题影响 1.7.10 ,但是仍然不是resolved所以..

问题

当我将eq('code', 'guitar')更改为'in'('code', ["guitar", "bass", "flute"])

我收到了错误:

org.codehaus.groovy.runtime.GStringImpl cannot be cast to java.lang.String

工作代码

//this code is working like expected 
def c = Project.createCriteria();
this.ids = c.list {
    projections {
        property 'id'
    }
    instruments{
        eq('code', 'guitar')
    }
}

NOT工作代码

//when I change the code to this one I get the error.
def c = Project.createCriteria();
this.ids = c.list {
    projections {
        property 'id'
    }
    instruments{
        //### This line create the problem!!
        'in'('code', ["guitar", "bass", "flute"])
    }
}

完整的堆栈跟踪错误:

org.codehaus.groovy.runtime.GStringImpl cannot be cast to java.lang.String. Stacktrace follows:
Message: org.codehaus.groovy.runtime.GStringImpl cannot be cast to java.lang.String
    Line | Method
->> 1618 | invokeMethod     in grails.orm.HibernateCriteriaBuilder
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    230 | search           in sound.domain.ProjectPagingService$$EOgryxiS
|    193 | search . . . . . in com.sound.ProjectController$$EOgrT45Y
|    150 | invoke           in net.bull.javamelody.JspWrapper
|    281 | invoke . . . . . in net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler
|     82 | doFilterInternal in com.linkedin.grails.profiler.ProfilerFilter
|    202 | doFilter . . . . in net.bull.javamelody.MonitoringFilter
|    180 | doFilter         in     ''
|   1145 | runWorker . . .  in java.util.concurrent.ThreadPoolExecutor
|    615 | run              in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . . . .  in java.lang.Thread

非常感谢任何帮助。

谢谢

1 个答案:

答案 0 :(得分:2)

问题似乎是你在列表中使用双引号,试试这个:

this.ids = Project.withCriteria {

    projections {
        property 'id'
    }

    instruments{
        'in'('code', ['guitar', 'bass', 'flute'])
    }
}