[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2052?page=c...
]
Peter Wyngaard commented on HHH-2052:
-------------------------------------
Me too, I've run into this bug. In my case, it's trying to create the DEBUG
message:
DEBUG org.hibernate.engine.CollectionLoadContext - creating collection
wrapper:[my.class.name#myId]
The collection it is trying to wrap is a ManyToMany association. Here is the annotation
on the getter:
@ManyToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
@JoinTable(
name="STUDY_PARAMETER_ASSIGN",
joinColumns={@JoinColumn(name="STUDY_ID",referencedColumnName="STUDY_ID")},
inverseJoinColumns={@JoinColumn(name="PARAMETER_VALUE_ID")}
)
Note the "referencedColumnName" in the JoinColumns. I have to include this
because the referenced column is not the primary key in the referenced table (due to
circumstances beyond our control...)
There is another class in the application that also has a ManyToMany association, but it
works just fine. Here is the annotation in that class:
@ManyToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
@JoinTable(
name="SAMPLE_PARAMETER_ASSIGN",
joinColumns={@JoinColumn(name="SAMPLE_ID")},
inverseJoinColumns={@JoinColumn(name="PARAMETER_VALUE_ID")}
)
Note that this class does not have the "referencedColumnName" annotation.
I'm employing the same workaround. I have put the following in my log4j.properties:
log4j.logger.org.hibernate.engine.CollectionLoadContext=INFO
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira