[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2052?page=c...
]
Nicholas White commented on HHH-2052:
-------------------------------------
I've got this too. My mapping is like:
<class name="MyClass" table="MyTable">
<id name="ThePkey" type="string" />
<property name="TheOtherId" type="integer" />
<set name="TheOtherSet" table="MyRows"
fetch="join" lazy="false" cascade="all">
<key column="ColumnA" property-ref="TheOtherId" />
<many-to-many column="ColumnB" class="MySecondClass"
/>
</set>
</class>
The problem is this bit of code (org.hibernate.pretty.MessageHelper lines 303-307
hibernate-core-3.3.1.GA.jar)
// 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 ) );
getOwnerEntityPersister returns the persistor for MyClass. getIdentifierType therefore
returns a StringType object as id property ThePkey is a String (see type attribute).
However, 'id' in the line above is the object referred to by the property-ref
attribute, i.e. is the value of TheOtherId. As TheOtherId is an Integer, the toString
method of StringType (called by toLoggableString) throws a ClassCastException (it's
expecting a String. (Why doesn't it just do 'value.toString()' instead of
'(String) value'?)
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 Core
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira