-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Possible bug with property-ref...need validation
PostPosted: Wed Nov 09, 2005 5:32 pm 
Beginner
Beginner

Joined: Mon Aug 22, 2005 1:22 am
Posts: 36
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


Top
 Profile  
 
 Post subject: You are correct :)
PostPosted: Tue Feb 27, 2007 3:58 pm 
Newbie

Joined: Thu Oct 19, 2006 10:39 pm
Posts: 9
Location: London
I have also seen this bug I am very grateful for your explanation which saved me allot of time.

Thanks,

James


Top
 Profile  
 
 Post subject: still a problem in 3.2.3 - below is reference to bug
PostPosted: Tue Apr 10, 2007 7:02 pm 
Newbie

Joined: Tue Apr 10, 2007 5:23 pm
Posts: 2
http://opensource.atlassian.com/project ... e/HHH-2052

Please vote for this bug!

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 24, 2007 2:05 pm 
Newbie

Joined: Tue Apr 24, 2007 1:58 pm
Posts: 1
You have a vote. How many more for them to fix it?

_________________
postcard printing and brochure printing


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.