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

Hibernate JIRA | Jan Snelders | 5 years ago
  1. 0

    I run into a ClassCastException(Integer cannot be cast to String) which I found out was related to one varchar field in one of my entities (Tests.java). For some reason hibernate assumes and treats this field as an integer and later runs into the reported ClassCastException. This only happens if the field is named "id" fully lowercase. Renaming this to "ID" solves the problem. This all happens while trying to create new Lucene indexes (fullTextEntityManager.createIndexer().startAndWait();) for Hibernate Search for my JPA2 entities using Hibernate as JPA2 provider. How to reproduce: Load the TestsTable.sql in your MySQL db (see attached zip) Set up the datasource in JBoss 6.1. (my datasource in excel file) Deploy a JPA project using the Tests table to the JBoss server (see persistence.xml and Tests.java) Try creating the indexes through JPA like ... @PersistenceContext(name="HeliumJPA") private EntityManager em; public void createSearchIndex(){ try { System.out.println("Start Lucene Indexing"); FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em); fullTextEntityManager.createIndexer().startAndWait(); System.out.println("Lucene Indexing finished"); } catch (InterruptedException e) { e.printStackTrace(); } } You will get the ClassCastException: 16:40:46,872 ERROR [org.hibernate.search.batchindexing.IdentifierConsumerEntityProducer] error during batch indexing: : java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String at org.hibernate.type.descriptor.java.StringTypeDescriptor.unwrap(StringTypeDescriptor.java:40) [:3.6.6.Final] at org.hibernate.type.descriptor.sql.VarcharTypeDescriptor$1.doBind(VarcharTypeDescriptor.java:52) [:3.6.6.Final] at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:91) [:3.6.6.Final] at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:283) [:3.6.6.Final] at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:278) [:3.6.6.Final] at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1873) [:3.6.6.Final] at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1844) [:3.6.6.Final] at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1716) [:3.6.6.Final] at org.hibernate.loader.Loader.doQuery(Loader.java:801) [:3.6.6.Final] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274) [:3.6.6.Final] at org.hibernate.loader.Loader.doList(Loader.java:2533) [:3.6.6.Final] at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276) [:3.6.6.Final] at org.hibernate.loader.Loader.list(Loader.java:2271) [:3.6.6.Final] at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119) [:3.6.6.Final] at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1716) [:3.6.6.Final] at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347) [:3.6.6.Final] at org.hibernate.search.batchindexing.IdentifierConsumerEntityProducer.loadList(IdentifierConsumerEntityProducer.java:141) [:3.4.1.Final] at org.hibernate.search.batchindexing.IdentifierConsumerEntityProducer.loadAllFromQueue(IdentifierConsumerEntityProducer.java:110) [:3.4.1.Final] at org.hibernate.search.batchindexing.IdentifierConsumerEntityProducer.run(IdentifierConsumerEntityProducer.java:87) [:3.4.1.Final] at org.hibernate.search.batchindexing.OptionallyWrapInJTATransaction.run(OptionallyWrapInJTATransaction.java:78) [:3.4.1.Final] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) [:1.6.0_27] at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [:1.6.0_27] at java.lang.Thread.run(Unknown Source) [:1.6.0_27]

    Hibernate JIRA | 5 years ago | Jan Snelders
    java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
  2. 0

    I run into a ClassCastException(Integer cannot be cast to String) which I found out was related to one varchar field in one of my entities (Tests.java). For some reason hibernate assumes and treats this field as an integer and later runs into the reported ClassCastException. This only happens if the field is named "id" fully lowercase. Renaming this to "ID" solves the problem. This all happens while trying to create new Lucene indexes (fullTextEntityManager.createIndexer().startAndWait();) for Hibernate Search for my JPA2 entities using Hibernate as JPA2 provider. How to reproduce: Load the TestsTable.sql in your MySQL db (see attached zip) Set up the datasource in JBoss 6.1. (my datasource in excel file) Deploy a JPA project using the Tests table to the JBoss server (see persistence.xml and Tests.java) Try creating the indexes through JPA like ... @PersistenceContext(name="HeliumJPA") private EntityManager em; public void createSearchIndex(){ try { System.out.println("Start Lucene Indexing"); FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em); fullTextEntityManager.createIndexer().startAndWait(); System.out.println("Lucene Indexing finished"); } catch (InterruptedException e) { e.printStackTrace(); } } You will get the ClassCastException: 16:40:46,872 ERROR [org.hibernate.search.batchindexing.IdentifierConsumerEntityProducer] error during batch indexing: : java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String at org.hibernate.type.descriptor.java.StringTypeDescriptor.unwrap(StringTypeDescriptor.java:40) [:3.6.6.Final] at org.hibernate.type.descriptor.sql.VarcharTypeDescriptor$1.doBind(VarcharTypeDescriptor.java:52) [:3.6.6.Final] at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:91) [:3.6.6.Final] at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:283) [:3.6.6.Final] at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:278) [:3.6.6.Final] at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1873) [:3.6.6.Final] at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1844) [:3.6.6.Final] at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1716) [:3.6.6.Final] at org.hibernate.loader.Loader.doQuery(Loader.java:801) [:3.6.6.Final] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274) [:3.6.6.Final] at org.hibernate.loader.Loader.doList(Loader.java:2533) [:3.6.6.Final] at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276) [:3.6.6.Final] at org.hibernate.loader.Loader.list(Loader.java:2271) [:3.6.6.Final] at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119) [:3.6.6.Final] at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1716) [:3.6.6.Final] at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347) [:3.6.6.Final] at org.hibernate.search.batchindexing.IdentifierConsumerEntityProducer.loadList(IdentifierConsumerEntityProducer.java:141) [:3.4.1.Final] at org.hibernate.search.batchindexing.IdentifierConsumerEntityProducer.loadAllFromQueue(IdentifierConsumerEntityProducer.java:110) [:3.4.1.Final] at org.hibernate.search.batchindexing.IdentifierConsumerEntityProducer.run(IdentifierConsumerEntityProducer.java:87) [:3.4.1.Final] at org.hibernate.search.batchindexing.OptionallyWrapInJTATransaction.run(OptionallyWrapInJTATransaction.java:78) [:3.4.1.Final] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) [:1.6.0_27] at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [:1.6.0_27] at java.lang.Thread.run(Unknown Source) [:1.6.0_27]

    Hibernate JIRA | 5 years ago | Jan Snelders
    java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    Java store room | java web development | Java | Struts | Hibernate : java.lang.Integer cannot be cast to java.lang.String

    blogspot.com | 7 months ago
    java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
  5. 0

    Patron searching - Funding date range search throws error

    GitHub | 6 years ago | StevensBrian
    java.lang.ClassCastException: java.util.Date cannot be cast to java.lang.String

  1. mortalman7 1 times, last 5 months ago
3 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.Integer cannot be cast to java.lang.String

    at org.hibernate.type.descriptor.java.StringTypeDescriptor.unwrap()
  2. Hibernate
    CriteriaLoader.list
    1. org.hibernate.type.descriptor.java.StringTypeDescriptor.unwrap(StringTypeDescriptor.java:40)[:3.6.6.Final]
    2. org.hibernate.type.descriptor.sql.VarcharTypeDescriptor$1.doBind(VarcharTypeDescriptor.java:52)[:3.6.6.Final]
    3. org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:91)[:3.6.6.Final]
    4. org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:283)[:3.6.6.Final]
    5. org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:278)[:3.6.6.Final]
    6. org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1873)[:3.6.6.Final]
    7. org.hibernate.loader.Loader.bindParameterValues(Loader.java:1844)[:3.6.6.Final]
    8. org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1716)[:3.6.6.Final]
    9. org.hibernate.loader.Loader.doQuery(Loader.java:801)[:3.6.6.Final]
    10. org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)[:3.6.6.Final]
    11. org.hibernate.loader.Loader.doList(Loader.java:2533)[:3.6.6.Final]
    12. org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)[:3.6.6.Final]
    13. org.hibernate.loader.Loader.list(Loader.java:2271)[:3.6.6.Final]
    14. org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)[:3.6.6.Final]
    14 frames
  3. Hibernate
    CriteriaImpl.list
    1. org.hibernate.impl.SessionImpl.list(SessionImpl.java:1716)[:3.6.6.Final]
    2. org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)[:3.6.6.Final]
    2 frames
  4. Hibernate Search Engine
    OptionallyWrapInJTATransaction.run
    1. org.hibernate.search.batchindexing.IdentifierConsumerEntityProducer.loadList(IdentifierConsumerEntityProducer.java:141)[:3.4.1.Final]
    2. org.hibernate.search.batchindexing.IdentifierConsumerEntityProducer.loadAllFromQueue(IdentifierConsumerEntityProducer.java:110)[:3.4.1.Final]
    3. org.hibernate.search.batchindexing.IdentifierConsumerEntityProducer.run(IdentifierConsumerEntityProducer.java:87)[:3.4.1.Final]
    4. org.hibernate.search.batchindexing.OptionallyWrapInJTATransaction.run(OptionallyWrapInJTATransaction.java:78)[:3.4.1.Final]
    4 frames
  5. Java RT
    Thread.run
    1. java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)[:1.6.0_27]
    2. java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)[:1.6.0_27]
    3. java.lang.Thread.run(Unknown Source)[:1.6.0_27]
    3 frames