[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2052) org.hibernate.pretty.MessageHelper.collectionInfoString tries to cast wrong object to String, causes ClassCastException
Francis (JIRA)
noreply at atlassian.com
Tue Apr 10 17:22:06 EDT 2007
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2052?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_26679 ]
Francis commented on HHH-2052:
------------------------------
This happens on 3.2.3, and happens when using a Bag/OneToMany with a reference to <properties> on both sides (A composite FK is used for the join), of course only when tracing is enabled.
I think the offending code is here (in MessageHelper):
public static String collectionInfoString(
CollectionPersister persister,
Serializable id,
SessionFactoryImplementor factory) {
StringBuffer s = new StringBuffer();
s.append( '[' );
if ( persister == null ) {
s.append( "<unreferenced>" );
}
else {
s.append( persister.getRole() );
s.append( '#' );
if ( id == null ) {
s.append( "<null>" );
}
else {
// Need to use the identifier type of the collection owner
// since the incoming is value is actually the owner's id.
// Using the collection's key type causes problems with
// property-ref keys...
>>>>> s.append( persister.getOwnerEntityPersister().getIdentifierType().toLoggableString( id, factory ) );
}
}
s.append( ']' );
return s.toString();
Isn't it funny the frequency that there are problems with code that requires an extensive comment?
Sorry I don't know the internals well enough to come up with a patch.
Thread [main] (Suspended (exception ClassCastException))
StringType.toString(Object) line: 44
StringType(NullableType).toLoggableString(Object, SessionFactoryImplementor) line: 218
MessageHelper.collectionInfoString(CollectionPersister, Serializable, SessionFactoryImplementor) line: 284
OneToManyLoader(Loader).loadCollection(SessionImplementor, Serializable, Type) line: 1986
OneToManyLoader(CollectionLoader).initialize(Serializable, SessionImplementor) line: 36
OneToManyPersister(AbstractCollectionPersister).initialize(Serializable, SessionImplementor) line: 565
DefaultInitializeCollectionEventListener.onInitializeCollection(InitializeCollectionEvent) line: 60
SessionImpl.initializeCollection(PersistentCollection, boolean) line: 1716
PersistentBag(AbstractPersistentCollection).forceInitialization() line: 454
StatefulPersistenceContext.initializeNonLazyCollections() line: 785
QueryLoader(Loader).loadSingleRow(ResultSet, SessionImplementor, QueryParameters, boolean) line: 294
ScrollableResultsImpl.prepareCurrentRow(boolean) line: 231
ScrollableResultsImpl.next() line: 100
DatabaseReader.parse(InputSource) line: 173
...
> 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: Hibernate3
> 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.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list