Hibernate version: 3.0.5
Mapping documents:
Code:
<hibernate-mapping>
<class name="hib.test.Tournament" table="TEST_TOURNAMENT" >
<id name="objectId" column="OID" type="long" >
<generator class="native"/>
</id>
<property name="zipCode" column="ADDR_ZIP_CODE"
type="string" insert="false" update="false" />
<set name="postalCodes">
<key column="ZIP_CODE" property-ref="zipCode" />
<one-to-many class="hib.test.PostalCode" />
</set>
</class>
<class name="hib.test.PostalCode"
table="TEST_POSTAL_CODE" mutable="false" >
<composite-id name="id"
class="hib.test.PostalCode$Id" >
<key-property name="city" column="CITY"
type="string" />
<key-property name="stateCode" column="STATE_CODE"
type="string" />
<key-property name="zipCode" column="ZIP_CODE"
type="string" />
<key-property name="countryCode" column="COUNTRY_CODE"
type="string" />
</composite-id>
<property name="cityType" column="CITY_TYPE"
type="string" />
<property name="zipCodeType" column="ZIP_CODE_TYPE"
type="string" />
<property name="areaCode" column="AREA_CODE"
type="string" />
<property name="longitude" column="LONGITUDE"
type="double" />
<property name="latitude" column="LATITUDE"
type="double" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Tournament tournament = null;
Session session = null;
try {
session = HibernateUtil.currentSession();
HibernateUtil.beginTransaction();
tournament = new Tournament();
tournament.setZipCode( "60175" );
session.save( tournament );
HibernateUtil.commitTransaction();
}
catch ( Exception e ) {
HibernateUtil.rollbackTransaction();
throw e;
}
finally {
HibernateUtil.closeSession();
}
try {
session = HibernateUtil.currentSession();
tournament = (Tournament)session.get( Tournament.class, tournament.getObjectId() );
}
finally {
HibernateUtil.closeSession();
}
try {
session = HibernateUtil.currentSession();
HibernateUtil.beginTransaction();
session.delete( tournament );
HibernateUtil.commitTransaction();
}
catch ( Exception e ) {
HibernateUtil.rollbackTransaction();
throw e;
}
finally {
HibernateUtil.closeSession();
}
Full stack trace of any exception that occurs:
java.lang.ClassCastException
at org.hibernate.type.StringType.toString(StringType.java:42)
at org.hibernate.type.NullableType.toLoggableString(NullableType.java:122)
at org.hibernate.pretty.MessageHelper.collectionInfoString(MessageHelper.java:187)
at org.hibernate.event.def.ReattachVisitor.removeCollection(ReattachVisitor.java:70)
at org.hibernate.event.def.OnUpdateVisitor.processCollection(OnUpdateVisitor.java:65)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:104)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:64)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:58)
at org.hibernate.event.def.AbstractVisitor.process(AbstractVisitor.java:129)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:74)
at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:579)
at hib.test.TestPropertyRef.testQuery(TestPropertyRef.java:57)
at hib.TestCase.runTest(TestCase.java:141)
Name and version of the database you are using:
MySql 5.0.15nt
The problem arises when I enable debugging. (log4j.logger.org.hibernate=debug) When disabled, it works fine.
It appears that when printing out debugging information, the id of the owning object (Tournament) is printed instead of the value of the property-ref. Since these are of different types (String vs Long) there is a class cast exception.
Can someone verify this is truly a bug or I have misconstrued how to do property ref associations?
Thanks
- Doug
P.S. if verified a bug, I will submit to JIRA