2

Issue: When trying to use Collection Set within namedParameters of ExecuteQuery It throws: java.lang.ClassCastException java.util.LinkedHashSet cannot be cast to java.lang.Long

I can convert the Set to data type List but I was wondering why this was now occurring in Grails 3.1.11 when it didn't appear to occur in Grails 2.2.3 . Is Is this a genuine bug in 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]
)

Part of the Stack trace

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
P.J.Meisch
  • 18,013
  • 6
  • 50
  • 66
Hacked Child
  • 91
  • 1
  • 5
  • If you think this is a bug, you might be better off just submitting it as such to the grails project. Will likely be seen quicker by someone in the know than SO. https://github.com/grails/grails-core/issues – Gregg Oct 19 '16 at 18:28

2 Answers2

1

Try with the :ids inside parenthesis.

List accountNameList  = AccountExample.executeQuery(
   "SELECT name FROM AccountExample WHERE id IN (:ids)",
   [ids:idList]
)
quindimildev
  • 1,280
  • 8
  • 21
0

It was acknowledged as a bug in 3.1.11 https://github.com/grails/grails-core/issues/10250

Hacked Child
  • 91
  • 1
  • 5