问题: 尝试在 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