Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing a java.util.Set as a named parameter to a HQL query causes ClassCastException #10250

Closed
HackedChild opened this issue Oct 20, 2016 · 1 comment

Comments

@HackedChild
Copy link

HackedChild commented Oct 20, 2016

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 Collection Set to data type Collection List and it will work, 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 this a genuine bug in Grails 3.1.11?

Expected Behaviour

ExecuteQuery handles named parameter of data type Collection Set just as it does with Collection List

Actual Behaviour

ClassCastException: java.util.LinkedHashSet cannot be cast to java.lang.Long

Example Code to Reproduce Issue

// A Mocked up Domain
class AccountExample {
   Long id
   String name
}
//Code that works
List idList = [2L, 3L, 5L, 7L, 11L, 13L]
List accountNameList1  = AccountExample.executeQuery(
   "SELECT name FROM AccountExample WHERE id IN :ids", [ids:idList]
)
List accountNameList2  = 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 accountNameList3  = AccountExample.executeQuery(
   "SELECT name FROM AccountExample WHERE id IN :ids", [ids:idSet]
)
List accountNameList4  = AccountExample.executeQuery(
   "SELECT name FROM AccountExample WHERE id IN (:ids)", [ids:idSet]
)

Stacktrace

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

Environment Information

  • Operating System: Windows 7 Enterprise 64-bit
  • Grails Version: 3.1.11
  • Groovy Version: 2.4.7
  • JVM Version: 1.8.0_102
@graemerocher graemerocher changed the title Is this a bug in Grails 3.1.11? I'm using Collection Set within namedParams of executeQuery and it causes java.lang.ClassCastException Passing a java.util.Set as a named parameter to a HQL query causes java.lang.ClassCastException Oct 20, 2016
@graemerocher graemerocher changed the title Passing a java.util.Set as a named parameter to a HQL query causes java.lang.ClassCastException Passing a java.util.Set as a named parameter to a HQL query causes ClassCastException Oct 20, 2016
@jameskleeh jameskleeh self-assigned this Oct 20, 2016
@jameskleeh
Copy link
Contributor

Fixed by grails/grails-data-mapping@490c2cd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants