问题: 尝试在ExecuteQuery的namedParameters中使用Collection Set时 抛出:java.lang.ClassCastException java.util.LinkedHashSet无法强制转换为java.lang.Long
我可以将Set转换为数据类型List,但我想知道为什么现在Grails 3.1.11中出现这种情况时,它似乎不会出现在Grails 2.2.3中。这是Grails 3.1.11中的真正错误吗?
// A Mocked up Domain
class AccountExample {
Long id
String name
}
//Code that works
List idList = [2L, 3L, 5L, 7L, 11L, 13L]
List accountNameList = AccountExample.executeQuery(
"SELECT name FROM AccountExample WHERE id IN :ids",
[ids:idList]
)
//Code that fails in Grails 3.1.11 but not in Grails 2.2.3
Set idSet = [2L, 3L, 5L, 7L, 11L, 13L]
List accountNameList = AccountExample.executeQuery(
"SELECT name FROM AccountExample WHERE id IN :ids",
[ids:idSet]
)
堆栈跟踪的一部分
Caused by ClassCastException: java.util.LinkedHashSet cannot be cast to java.lang.Long
->> 36 | unwrap in org.hibernate.type.descriptor.java.LongTypeDescriptor
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 63 | doBind in org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$1
| 90 | bind . . . . . . in org.hibernate.type.descriptor.sql.BasicBinder
| 286 | nullSafeSet in org.hibernate.type.AbstractStandardBasicType
| 281 | nullSafeSet . . in ''
| 67 | bind in org.hibernate.param.NamedParameterSpecification
| 616 | bindParameterValues in org.hibernate.loader.hql.QueryLoader
| 1901 | prepareQueryStatement in org.hibernate.loader.Loader
| 1862 | executeQueryStatement in ''
| 1839 | executeQueryStatement in ''
| 910 | doQuery . . . . in ''
| 355 | doQueryAndInitializeNonLazyCollections in ''
| 2554 | doList . . . . . in ''
| 2540 | doList in ''
| 2370 | listIgnoreQueryCache in ''
| 2365 | list in ''
| 497 | list . . . . . . in org.hibernate.loader.hql.QueryLoader
| 387 | list in org.hibernate.hql.internal.ast.QueryTranslatorImpl
| 236 | performList . . in org.hibernate.engine.query.spi.HQLQueryPlan
| 1300 | list in org.hibernate.internal.SessionImpl
| 103 | list . . . . . . in org.hibernate.internal.QueryImpl
| 311 | doCall in org.grails.orm.hibernate.AbstractHibernateGormStaticApi$_executeQuery_closure12
| 196 | doExecute . . . in org.grails.orm.hibernate.GrailsHibernateTemplate
| 140 | execute in ''
| 110 | execute . . . . in ''
| 303 | executeQuery in org.grails.orm.hibernate.AbstractHibernateGormStaticApi
| 892 | executeQuery . . in org.grails.datastore.gorm.GormStaticApi
| 1026 | executeQuery in org.grails.datastore.gorm.GormEntity$Trait$Helper
答案 0 :(得分:1)
尝试使用括号内的:ids。
List accountNameList = AccountExample.executeQuery(
"SELECT name FROM AccountExample WHERE id IN (:ids)",
[ids:idList]
)
答案 1 :(得分:0)
它被认为是3.1.11中的错误 https://github.com/grails/grails-core/issues/10250