[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2052) org.hibernate.pretty.MessageHelper.collectionInfoString tries to cast wrong object to String, causes ClassCastException

Prem (JIRA) noreply at atlassian.com
Tue Jan 24 11:33:27 EST 2012


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2052?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45231#comment-45231 ] 

Prem commented on HHH-2052:
---------------------------

CalssCastException

HBM snippet:
<class name="com.test.ReportApp" table="INV_REPAPP">
  <composite-id mapped="false" unsaved-value="undefined">
   <key-property name="reportid" type="int">
    <column name="REPORTID"/>
   </key-property>
  </composite-id>
  <property generated="never" lazy="false" name="appgroupid" type="string">
   <column length="60" name="APPGROUPID"/>
  </property>
  <property generated="never" lazy="false" name="appid" type="string">
   <column length="60" name="APPID"/>
  </property>
  <property generated="never" lazy="false" name="reportno" type="string">
   <column length="30" name="REPORTNO"/>
  </property>
  <property generated="never" lazy="false" name="reportname" type="string">
   <column length="100" name="REPORTNAME"/>
  </property>
  <property generated="never" lazy="false" name="recordclasscode" type="string">
   <column length="6" name="RECORDCLASSCODE"/>
  </property>
  <property generated="never" lazy="false" name="folderid" type="string">
   <column length="60" name="FOLDERID"/>
  </property>
  <property generated="never" lazy="false" name="inventoryId" type="int">
   <column name="INVENTORY_ID" unique="true"/>
  </property>

  <property generated="never" lazy="false" name="expirationtype" type="string">
   <column length="16" name="EXPIRATIONTYPE"/>
  </property>
<set name="ilmFields" table="INV_REPILM" >
    <key  column="INVENTORY_ID" property-ref="inventoryId" update="false" />
    <one-to-many  entity-name="com.test.Repilm" not-found="exception" />
</set>
 </class>

-------------------------------------
Error:

org.hibernate.PropertyAccessException: Exception occurred inside setter of com.test.ReportApp.ilmFields
	at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:89) [hibernate3.jar:na]
	at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:352) [hibernate3.jar:na]
	at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:232) [hibernate3.jar:na]
	at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3580) [hibernate3.jar:na]
	at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:152) [hibernate3.jar:na]
	at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:877) [hibernate3.jar:na]
	at org.hibernate.loader.Loader.doQuery(Loader.java:752) [hibernate3.jar:na]
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) [hibernate3.jar:na]
	at org.hibernate.loader.Loader.loadEntity(Loader.java:1885) [hibernate3.jar:na]
	at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:71) [hibernate3.jar:na]
	at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:65) [hibernate3.jar:na]
	at org.hibernate.loader.entity.BatchingEntityLoader.load(BatchingEntityLoader.java:105) [hibernate3.jar:na]
	at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3062) [hibernate3.jar:na]
	at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:434) [hibernate3.jar:na]
	at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:415) [hibernate3.jar:na]
	at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:165) [hibernate3.jar:na]
	at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:223) [hibernate3.jar:na]
	at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:126) [hibernate3.jar:na]
	at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:906) [hibernate3.jar:na]
	at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:874) [hibernate3.jar:na]
	at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:590) [hibernate3.jar:na]
	at org.hibernate.type.EntityType.resolve(EntityType.java:412) [hibernate3.jar:na]
	at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:139) [hibernate3.jar:na]
	at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:877) [hibernate3.jar:na]
	at org.hibernate.loader.Loader.doQuery(Loader.java:752) [hibernate3.jar:na]
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) [hibernate3.jar:na]
	at org.hibernate.loader.Loader.doList(Loader.java:2232) [hibernate3.jar:na]
	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129) [hibernate3.jar:na]
	at org.hibernate.loader.Loader.list(Loader.java:2124) [hibernate3.jar:na]
	at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401) [hibernate3.jar:na]
	at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363) [hibernate3.jar:na]
	at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) [hibernate3.jar:na]
	at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1149) [hibernate3.jar:na]
	at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) [hibernate3.jar:na]
	at org.springframework.orm.hibernate3.HibernateTemplate$34.doInHibernate(HibernateTemplate.java:1015) [org.springframework.orm.jar:3.0.0.RC1]
	at org.springframework.orm.hibernate3.HibernateTemplate$34.doInHibernate(HibernateTemplate.java:1) [org.springframework.orm.jar:3.0.0.RC1]
	at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406) [org.springframework.orm.jar:3.0.0.RC1]
	at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) [org.springframework.orm.jar:3.0.0.RC1]
	at org.springframework.orm.hibernate3.HibernateTemplate.findByNamedQueryAndNamedParam(HibernateTemplate.java:1006) [org.springframework.orm.jar:3.0.0.RC1]
	at com.msdw.ondemand.dao.hibernate.archivedw.ReportDaoImpl.getReportById(ReportDaoImpl.java:39) [build/:na]
	at com.msdw.ondemand.dao.archivedw.ReportDaoTest.getReport(ReportDaoTest.java:49) [build/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [na:1.6.0_27]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [na:1.6.0_27]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [na:1.6.0_27]
	at java.lang.reflect.Method.invoke(Method.java:597) [na:1.6.0_27]
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) [junit.jar:na]
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) [junit.jar:na]
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) [junit.jar:na]
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) [junit.jar:na]
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) [junit.jar:na]
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) [org.springframework.test.jar:3.0.0.RC1]
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82) [org.springframework.test.jar:3.0.0.RC1]
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) [org.springframework.test.jar:3.0.0.RC1]
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240) [org.springframework.test.jar:3.0.0.RC1]
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) [junit.jar:na]
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) [junit.jar:na]
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) [junit.jar:na]
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) [junit.jar:na]
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) [junit.jar:na]
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) [junit.jar:na]
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) [org.springframework.test.jar:3.0.0.RC1]
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) [org.springframework.test.jar:3.0.0.RC1]
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236) [junit.jar:na]
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180) [org.springframework.test.jar:3.0.0.RC1]
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) [.cp/:na]
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) [.cp/:na]
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) [.cp/:na]
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) [.cp/:na]
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) [.cp/:na]
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) [.cp/:na]
Caused by: java.lang.reflect.InvocationTargetException: null
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [na:1.6.0_27]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [na:1.6.0_27]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [na:1.6.0_27]
	at java.lang.reflect.Method.invoke(Method.java:597) [na:1.6.0_27]
	at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:66) [hibernate3.jar:na]
	... 69 common frames omitted
Caused by: java.lang.ClassCastException: java.lang.Integer
	at org.hibernate.type.ComponentType.toLoggableString(ComponentType.java:400) [hibernate3.jar:na]
	at org.hibernate.pretty.MessageHelper.collectionInfoString(MessageHelper.java:307) [hibernate3.jar:na]
	at org.hibernate.loader.Loader.loadCollection(Loader.java:2011) [hibernate3.jar:na]
	at org.hibernate.loader.collection.BatchingCollectionInitializer.initialize(BatchingCollectionInitializer.java:75) [hibernate3.jar:na]
	at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:587) [hibernate3.jar:na]
	at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83) [hibernate3.jar:na]
	at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1744) [hibernate3.jar:na]
	at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:366) [hibernate3.jar:na]
	at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108) [hibernate3.jar:na]
	at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:131) [hibernate3.jar:na]
	at org.hibernate.collection.PersistentSet.size(PersistentSet.java:162) [hibernate3.jar:na]
	at com.test.ReportApp.setIlmFields(ReportApp.java:43) [build/:na]
	... 74 common frames omitted



> org.hibernate.pretty.MessageHelper.collectionInfoString tries to cast wrong object to String, causes ClassCastException
> -----------------------------------------------------------------------------------------------------------------------
>
>                 Key: HHH-2052
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2052
>             Project: Hibernate ORM
>          Issue Type: Bug
>            Reporter: Tree 'Huggy Bear' Hugger
>         Attachments: bugtest.zip
>
>
> Debug level logging attempted by MessageHelper falls over when constructing a loggable string for a mapped collection on the main entity.
> Following the code in the stacktrace, I can see that MessageHelper expects the parent key for the collection relationship to be the primary key, but it is mapped to another field of a different type via a property-ref. Hence the ClassCastException below.
> The work around is to set logging to INFO or higher.
> I have also attached a pared-down zip with the maven 2 project containing the mappings and the unit test which fails.
> The following JIRA issue may be the same thing:
> http://opensource.atlassian.com/projects/hibernate/browse/ANN-298
> The following messages on the Hib forum demonstrate other interest in this issue:
> http://forum.hibernate.org/viewtopic.php?t=949913
> http://forum.hibernate.org/viewtopic.php?t=956778
> http://forum.hibernate.org/viewtopic.php?t=962471
> java.lang.ClassCastException: com.nomadsoft.cortex.domain.country.basic.BasicCountry
> 	at org.hibernate.type.StringType.toString(StringType.java:44)
> 	at org.hibernate.type.NullableType.toLoggableString(NullableType.java:168)
> 	at org.hibernate.pretty.MessageHelper.collectionInfoString(MessageHelper.java:284)
> 	at org.hibernate.loader.Loader.readCollectionElement(Loader.java:972)
> 	at org.hibernate.loader.Loader.readCollectionElements(Loader.java:635)
> 	at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
> 	at org.hibernate.loader.Loader.doQuery(Loader.java:689)
> 	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
> 	at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
> 	at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:47)
> 	at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:41)
> 	at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2730)
> 	at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365)
> 	at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
> 	at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
> 	at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:177)
> 	at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
> 	at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
> 	at org.hibernate.impl.SessionImpl.get(SessionImpl.java:799)
> 	at org.hibernate.impl.SessionImpl.get(SessionImpl.java:792)
> 	at org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:452)
> 	at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
> 	at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:446)
> 	at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:440)
> 	at com.nomadsoft.cortex.infrastructure.hibernate.HibernateCountryRepository.getById(HibernateCountryRepository.java:26)
> 	at com.nomadsoft.cortex.domain.country.basic.BasicCountryService.getCountry(BasicCountryService.java:34)
>         etc etc

--
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