java.lang.ClassCastException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • 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]
    via by Jan Snelders,
  • 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]
    via by Jan Snelders,
  • Searching by Publication date
    via GitHub by mhudspeth
    ,
  • Hibernate aliasToBean is not working
    via Stack Overflow by Nick Eng
    ,
    • 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]

    Users with the same issue

    mortalman7
    1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    tfr
    1 times, last one,