[hibernate-issues] [Hibernate-JIRA] Created: (HSEARCH-901) ClassCastException during creation of index: Hibernate (Search) assumes varchar entity field called "id" is an Integer but it isn't

Jan Snelders (JIRA) noreply at atlassian.com
Mon Sep 5 10:48:07 EDT 2011


ClassCastException during creation of index: Hibernate (Search) assumes varchar entity field called "id" is an Integer but it isn't
-----------------------------------------------------------------------------------------------------------------------------------

                 Key: HSEARCH-901
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-901
             Project: Hibernate Search
          Issue Type: Bug
          Components: massindexer
    Affects Versions: 3.4.1.Final
         Environment: Windows 7, Java 6.27 (x64), JBoss 6.1 using JPA2, Hibernate 3.6.6.Final, Lucene 3.1.0, MySQL driver 5.1.17, MySQL 5.1.47 (on linux CentOS 5.6 - 2.6.18-238.19.1.el5)
            Reporter: Jan Snelders
         Attachments: files.zip

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]


--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list