java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer

Hibernate JIRA | Cody Lerum | 5 years ago
  1. 0

    I have run into an issue after moving from Search 3.1 to 3.4.1 and later to 4.0.Beta2. The issue is that when loading an result entity from a hibernate search query the load fails if the result entity has an associated entity where the id types are dissimilar. For example if I have Company with an id type of Long and employee with id type of Integer and I search and the result is the company entity my search throws the following stack trace. {code} caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer at org.hibernate.type.descriptor.java.IntegerTypeDescriptor.unwrap(IntegerTypeDescriptor.java:36) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$1.doBind(IntegerTypeDescriptor.java:57) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:82) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:305) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:300) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1909) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1880) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1758) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.loader.Loader.doQuery(Loader.java:828) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.loader.Loader.doList(Loader.java:2449) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.loader.Loader.doList(Loader.java:2435) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.loader.Loader.list(Loader.java:2271) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:121) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1484) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:373) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.search.query.hibernate.impl.CriteriaObjectsInitializer.initializeObjects(CriteriaObjectsInitializer.java:107) [hibernate-search-orm-4.0.0.Beta2.jar:] at org.hibernate.search.query.hibernate.impl.QueryLoader.executeLoad(QueryLoader.java:91) [hibernate-search-orm-4.0.0.Beta2.jar:] at org.hibernate.search.query.hibernate.impl.AbstractLoader.load(AbstractLoader.java:72) [hibernate-search-orm-4.0.0.Beta2.jar:] at org.hibernate.search.query.hibernate.impl.FullTextQueryImpl.list(FullTextQueryImpl.java:211) [hibernate-search-orm-4.0.0.Beta2.jar:] at org.hibernate.search.jpa.impl.FullTextQueryImpl.getResultList(FullTextQueryImpl.java:147) [hibernate-search-orm-4.0.0.Beta2.jar:] at com.domain.search.SearchUtil.search(SearchUtil.java:55) [classes:] {code}

    Hibernate JIRA | 5 years ago | Cody Lerum
    java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
  2. 0

    I have run into an issue after moving from Search 3.1 to 3.4.1 and later to 4.0.Beta2. The issue is that when loading an result entity from a hibernate search query the load fails if the result entity has an associated entity where the id types are dissimilar. For example if I have Company with an id type of Long and employee with id type of Integer and I search and the result is the company entity my search throws the following stack trace. {code} caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer at org.hibernate.type.descriptor.java.IntegerTypeDescriptor.unwrap(IntegerTypeDescriptor.java:36) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$1.doBind(IntegerTypeDescriptor.java:57) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:82) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:305) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:300) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1909) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1880) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1758) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.loader.Loader.doQuery(Loader.java:828) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.loader.Loader.doList(Loader.java:2449) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.loader.Loader.doList(Loader.java:2435) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.loader.Loader.list(Loader.java:2271) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:121) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1484) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:373) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2] at org.hibernate.search.query.hibernate.impl.CriteriaObjectsInitializer.initializeObjects(CriteriaObjectsInitializer.java:107) [hibernate-search-orm-4.0.0.Beta2.jar:] at org.hibernate.search.query.hibernate.impl.QueryLoader.executeLoad(QueryLoader.java:91) [hibernate-search-orm-4.0.0.Beta2.jar:] at org.hibernate.search.query.hibernate.impl.AbstractLoader.load(AbstractLoader.java:72) [hibernate-search-orm-4.0.0.Beta2.jar:] at org.hibernate.search.query.hibernate.impl.FullTextQueryImpl.list(FullTextQueryImpl.java:211) [hibernate-search-orm-4.0.0.Beta2.jar:] at org.hibernate.search.jpa.impl.FullTextQueryImpl.getResultList(FullTextQueryImpl.java:147) [hibernate-search-orm-4.0.0.Beta2.jar:] at com.domain.search.SearchUtil.search(SearchUtil.java:55) [classes:] {code}

    Hibernate JIRA | 5 years ago | Cody Lerum
    java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
  3. 0

    Criteria: ClassCastException Integer to Long

    Stack Overflow | 3 years ago | Thiago Maltempi
    java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Can't use numeric filter in a lazy loading datatable: ClassCastException String to Integer

    Stack Overflow | 3 years ago | Guilherme
    java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

  1. tfr 1 times, last 7 months ago
2 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.lang.ClassCastException

    java.lang.Long cannot be cast to java.lang.Integer

    at org.hibernate.type.descriptor.java.IntegerTypeDescriptor.unwrap()
  2. Hibernate
    CriteriaImpl.list
    1. org.hibernate.type.descriptor.java.IntegerTypeDescriptor.unwrap(IntegerTypeDescriptor.java:36)[hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
    2. org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$1.doBind(IntegerTypeDescriptor.java:57)[hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
    3. org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:82)[hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
    4. org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:305)[hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
    5. org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:300)[hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
    6. org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1909)[hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
    7. org.hibernate.loader.Loader.bindParameterValues(Loader.java:1880)[hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
    8. org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1758)[hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
    9. org.hibernate.loader.Loader.doQuery(Loader.java:828)[hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
    10. org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)[hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
    11. org.hibernate.loader.Loader.doList(Loader.java:2449)[hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
    12. org.hibernate.loader.Loader.doList(Loader.java:2435)[hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
    13. org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)[hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
    14. org.hibernate.loader.Loader.list(Loader.java:2271)[hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
    15. org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:121)[hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
    16. org.hibernate.internal.SessionImpl.list(SessionImpl.java:1484)[hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
    17. org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:373)[hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
    17 frames
  3. Hibernate Search ORM
    FullTextQueryImpl.getResultList
    1. org.hibernate.search.query.hibernate.impl.CriteriaObjectsInitializer.initializeObjects(CriteriaObjectsInitializer.java:107)[hibernate-search-orm-4.0.0.Beta2.jar:]
    2. org.hibernate.search.query.hibernate.impl.QueryLoader.executeLoad(QueryLoader.java:91)[hibernate-search-orm-4.0.0.Beta2.jar:]
    3. org.hibernate.search.query.hibernate.impl.AbstractLoader.load(AbstractLoader.java:72)[hibernate-search-orm-4.0.0.Beta2.jar:]
    4. org.hibernate.search.query.hibernate.impl.FullTextQueryImpl.list(FullTextQueryImpl.java:211)[hibernate-search-orm-4.0.0.Beta2.jar:]
    5. org.hibernate.search.jpa.impl.FullTextQueryImpl.getResultList(FullTextQueryImpl.java:147)[hibernate-search-orm-4.0.0.Beta2.jar:]
    5 frames
  4. com.domain.search
    SearchUtil.search
    1. com.domain.search.SearchUtil.search(SearchUtil.java:55)[classes:]
    1 frame