-->
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.  [ 3 posts ] 
Author Message
 Post subject: ClassCastException for StringType.. removed type on mappings
PostPosted: Wed Oct 19, 2005 11:06 pm 
Newbie

Joined: Wed Oct 19, 2005 10:55 pm
Posts: 2
Hey there.

I read that ClassCastException for StringType are likely mapping discrepencies, so I've triple-checked my mapping types against my POJOs. I even removed the types alltogether. Yet, I'm still lost with this ClassCastException.

What am I missing? Thanks.

Hibernate version:
3.0.5 & 3.1rc1

Mapping documents and POJOs:
http://www.firestruck.com/temp/Patient.hbm.xml
http://www.firestruck.com/temp/Address.hbm.xml
http://www.firestruck.com/temp/Patient.java
http://www.firestruck.com/temp/Address.java

Full stack trace of any exception that occurs:
[java] 2843 [main] DEBUG org.hibernate.SQL - select patient0_.id as id0_, patient0_.dob as dob1_0_, patient0_.first_name as first3_1_0_, patient0_.gender as gender1_0_, patient0_.last_name as last5_1_0_, patient0_.middle_name as middle6_1_0_, patient0_.phone as phone1_0_, patient0_.ssn as ssn1_0_, patient0_.address_id as address9_1_0_ from patient patient0_ where patient0_.id=?
[java] Hibernate: select patient0_.id as id0_, patient0_.dob as dob1_0_, patient0_.first_name as first3_1_0_, patient0_.gender as gender1_0_, patient0_.last_name as last5_1_0_, patient0_.middle_name as middle6_1_0_, patient0_.phone as phone1_0_, patient0_.ssn as ssn1_0_, patient0_.address_id as address9_1_0_ from patient patient0_ where patient0_.id=?
[java] 2843 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
[java] 2843 [main] DEBUG org.hibernate.type.IntegerType - binding '104' to parameter: 1
[java] 2859 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
[java] 2859 [main] DEBUG org.hibernate.loader.Loader - processing result set
[java] 2859 [main] DEBUG org.hibernate.loader.Loader - result set row: 0
[java] 2859 [main] DEBUG org.hibernate.loader.Loader - result row: EntityKey[com.bea.medrec.domain.Patient#104]
[java] 2859 [main] DEBUG org.hibernate.loader.Loader - Initializing object from ResultSet: [com.bea.medrec.domain.Patient#104]
[java] 2875 [main] DEBUG org.hibernate.persister.entity.BasicEntityPersister - Hydrating entity: [com.bea.medrec.domain.Patient#104]
[java] 2875 [main] DEBUG org.hibernate.type.DateType - returning '17 August 1971' as column: dob1_0_
[java] 2875 [main] DEBUG org.hibernate.type.StringType - returning 'Gabrielle' as column: first3_1_0_
[java] 2875 [main] DEBUG org.hibernate.type.StringType - returning 'Female' as column: gender1_0_
[java] 2875 [main] DEBUG org.hibernate.type.StringType - returning 'Spiker' as column: last5_1_0_
[java] 2875 [main] DEBUG org.hibernate.type.StringType - returning 'H' as column: middle6_1_0_
[java] 2875 [main] DEBUG org.hibernate.type.StringType - returning '4151234564' as column: phone1_0_
[java] 2875 [main] DEBUG org.hibernate.type.StringType - returning '333333333' as column: ssn1_0_
[java] 2875 [main] DEBUG org.hibernate.type.IntegerType - returning '101' as column: address9_1_0_
[java] 2875 [main] DEBUG org.hibernate.loader.Loader - done processing result set (1 rows)
[java] 2875 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
[java] 2890 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
[java] 2890 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
[java] 2890 [main] DEBUG org.hibernate.loader.Loader - total objects hydrated: 1
[java] 2890 [main] DEBUG org.hibernate.engine.TwoPhaseLoad - resolving associations for [com.bea.medrec.domain.Patient#104]
[java] 2890 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener - loading entity: [com.bea.medrec.domain.Address#101]
[java] 2890 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener - creating new proxy for entity
[java] 2890 [main] DEBUG org.hibernate.jdbc.JDBCContext - after autocommit
[java] 2890 [main] DEBUG org.hibernate.impl.SessionImpl - after transaction completion
[java] 2890 [main] DEBUG org.springframework.orm.hibernate3.HibernateTemplate - Not closing pre-bound Hibernate Session after HibernateTemplate
[java] java.lang.ClassCastException: java.lang.Integer
[java] at org.hibernate.type.StringType.toString(StringType.java:42)
[java] at org.hibernate.type.NullableType.toLoggableString(NullableType.java:122)
[java] at org.hibernate.pretty.MessageHelper.infoString(MessageHelper.java:68)
[java] at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:143)
[java] at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:79)
[java] at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:655)
[java] at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:261)
[java] at org.hibernate.type.EntityType.resolve(EntityType.java:286)
[java] at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:105)
[java] at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:530)
[java] at org.hibernate.loader.Loader.doQuery(Loader.java:436)
[java] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
[java] at org.hibernate.loader.Loader.loadEntity(Loader.java:1345)
[java] at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:116)
[java] at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:101)
[java] at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2471)
[java] at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:351)
[java] at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:332)
[java] at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:113)
[java] at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:167)
[java] at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:79)
[java] at org.hibernate.impl.SessionImpl.get(SessionImpl.java:621)
[java] at org.hibernate.impl.SessionImpl.get(SessionImpl.java:614)
[java] at org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:443)
[java] at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:358)
[java] at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:437)
[java] at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:432)
[java] at com.bea.medrec.dao.orm.HibernatePatientDao.getById(HibernatePatientDao.java:28)
[java] at JdbcPatientDaoTest.testGetById(JdbcPatientDaoTest.java:74)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:585)
[java] at junit.framework.TestCase.runTest(TestCase.java:154)
[java] at junit.framework.TestCase.runBare(TestCase.java:127)
[java] at junit.framework.TestResult$1.protect(TestResult.java:106)
[java] at junit.framework.TestResult.runProtected(TestResult.java:124)
[java] at junit.framework.TestResult.run(TestResult.java:109)
[java] at junit.framework.TestCase.run(TestCase.java:118)
[java] at junit.framework.TestSuite.runTest(TestSuite.java:208)
[java] at junit.framework.TestSuite.run(TestSuite.java:203)
[java] at junit.textui.TestRunner.doRun(TestRunner.java:116)
[java] at junit.textui.TestRunner.doRun(TestRunner.java:109)
[java] at junit.textui.TestRunner.run(TestRunner.java:72)
[java] at JdbcPatientDaoTest.main(JdbcPatientDaoTest.java:289)
[java] 2890 [main] DEBUG org.springframework.jdbc.datasource.DataSourceTransactionManager - Triggering beforeCompletion synchronization
[java] 2890 [main] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager - Removed value [org.springframework.orm.hibernate3.SessionHolder@14b6bed] for key [org.hibernate.impl.SessionFactoryImpl@9aba32] from thread [main]

Name and version of the database you are using:
PointBase & MySQL

Debug level Hibernate log excerpt:
Complete log:
http://www.firestruck.com/temp/test.out


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 12:13 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
both of your identifiers are integers. when you call Session.get, are you passing a String as the second parameter?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 11:11 am 
Newbie

Joined: Wed Oct 19, 2005 10:55 pm
Posts: 2
Resolved.

The issue was with the Patient-User association. The assoication is one-to-one, but does not share a common identifier. Rather, the association is linked via foreign key. Because Patent.Id is an integer and User.Username is a string, a type conflict arouse.

For one-to-one associations via a foreign key, the objects must be mapped using the many-to-one and one-to-one configurations.

A better explanation can be found here:
http://www.informit.com/guides/content.asp?g=java&seqNum=148&rl=1 (see "One-to-One Relationship").


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.