0
我将我的代码库从Grails 2.1.0升级到3.2.0。但是,我遇到了一种情况,即我的某个查询未按预期工作。Grails GORM 3.2.0查询,其中列出的值在哪里
public List<Location> findAllLocationsByNames(Collection<String> placeNames) {
return Location.executeQuery("select l from Location l where l.placeName in (:placeNames)", [placeNames: placeNames])
}
升级之前,此查询运行良好。我通过了一个类型为LinkedKeySet
(来自HashMap.getKeySet()
)的集合,它正确返回位置列表。但现在使用Grails的新版本,我得到这个错误:
java.util.LinkedHashMap$LinkedKeySet cannot be cast to java.lang.String
我挖一个深一点内部Grails和格姆,看到QueryTranslatorImpl翻译命名参数placeNames
到SQL AST作为[NAMED_PARAM] ParameterNode: '?' {name=placeNames, [email protected]}
,但我不知道为什么。
最后,我改变了原来的查询中使用where
和的DetachedCriteria:
public List<Location> findAllLocationsByNames(Collection<String> placeNames) {
return Location.where {placeName in placeNames}.list()
}
这一次,一切工作正常,返回的结果是我所期待的。
使用executeQuery
的第一个查询有什么问题?
你是对的,谢谢!你知道那里发生了什么变化吗? –