-->
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.  [ 7 posts ] 
Author Message
 Post subject: Classcast exception when starting up
PostPosted: Mon Jun 12, 2006 11:26 am 
Newbie

Joined: Sun Jun 11, 2006 4:02 pm
Posts: 3
Hi, just getting started with hibernate. Converted an existing schema on oracle and during the initialization of session factory getting a classcast exception. I am not sure where to start looking for the trouble spot.

I am using hibernate tools to generate the hbm and DAO files. Not attaching those here since there are too many. But if needed I can do that in the followup.

Thanks a lot!
Mir

Hibernate version: 3.1

Mapping documents:
hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.password">ab2</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:ab2</property>
<property name="hibernate.connection.username">ab2</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.default_schema">AB2</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
<mapping resource="com/earthlink/hibernation/EmailAddresses.hbm.xml" />
<mapping resource="com/earthlink/hibernation/Organizations.hbm.xml" />
<mapping resource="com/earthlink/hibernation/Events.hbm.xml" />
<mapping resource="com/earthlink/hibernation/Images.hbm.xml" />
<mapping resource="com/earthlink/hibernation/CollectionsContacts.hbm.xml" />
<mapping resource="com/earthlink/hibernation/Notes.hbm.xml" />
<mapping resource="com/earthlink/hibernation/ExternalidsInternalids.hbm.xml" />
<mapping resource="com/earthlink/hibernation/GeographicPositions.hbm.xml" />
<mapping resource="com/earthlink/hibernation/Contacts.hbm.xml" />
<mapping resource="com/earthlink/hibernation/MiscellaneousAttributes.hbm.xml" />
<mapping resource="com/earthlink/hibernation/ImAddresses.hbm.xml" />
<mapping resource="com/earthlink/hibernation/AdditionalProperties.hbm.xml" />
<mapping resource="com/earthlink/hibernation/NotableUrls.hbm.xml" />
<mapping resource="com/earthlink/hibernation/SipUris.hbm.xml" />
<mapping resource="com/earthlink/hibernation/PhysicalAddresses.hbm.xml" />
<mapping resource="com/earthlink/hibernation/PhoneNumbers.hbm.xml" />
<mapping resource="com/earthlink/hibernation/Collections.hbm.xml" />
</session-factory>
</hibernate-configuration>

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Initial SessionFactory creation failed java.lang.ClassCastException: org.hibernate.type.StringType
java.lang.ClassCastException: org.hibernate.type.StringType
at org.hibernate.tuple.PropertyFactory.buildVersionProperty(PropertyFactory.java:83)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:157)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:412)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:108)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:216)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
at com.earthlink.hibernation.HibernateUtil.<clinit>(HibernateUtil.java:25)
at com.earthlink.hibernation.TestHibernate.main(TestHibernate.java:38)
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.earthlink.hibernation.HibernateUtil.<clinit>(HibernateUtil.java:31)
at com.earthlink.hibernation.TestHibernate.main(TestHibernate.java:38)
Caused by: java.lang.ClassCastException: org.hibernate.type.StringType
at org.hibernate.tuple.PropertyFactory.buildVersionProperty(PropertyFactory.java:83)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:157)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:412)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:108)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:216)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
at com.earthlink.hibernation.HibernateUtil.<clinit>(HibernateUtil.java:25)
... 1 more


Name and version of the database you are using:

Oracle 10g

The generated SQL (show_sql=true):

NA

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 12, 2006 1:01 pm 
Newbie

Joined: Sun Jun 11, 2006 4:02 pm
Posts: 3
Here is a bit more information after turning on all the logging I see the exception thrown around here (bunch of logline before this):

6020 [main] DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Delete 0: delete from AB2.EMAIL_ADDRESSES where EMAIL_ADDRESS_ID=?
Initial SessionFactory creation failed java.lang.ClassCastException: org.hibernate.type.StringType
java.lang.ClassCastException: org.hibernate.type.StringType
at org.hibernate.tuple.PropertyFactory.buildVersionProperty(PropertyFactory.java:83)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:157)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:412)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:108)


So it seems like when trying to map a delete command it is failing because it is expecting the StringType? The EMAIL_ADDRESS_ID column in oracle is a number which is mapped as BigDecmial as I understand.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 12, 2006 9:26 pm 
Newbie

Joined: Sun Jun 11, 2006 4:02 pm
Posts: 3
ok after poking around a lot looks like the problem is caused by one of the columns in my table. One of the column name is "version" and that seems to be the cause of the problem. Once I renamed the column, the issue went away.

I did not see any mention of "version" being reserved name for columns. Can someone offer any insight?

Thanks


Top
 Profile  
 
 Post subject: ClassCastException when existing table has "version&quo
PostPosted: Thu Jun 15, 2006 2:05 pm 
Newbie

Joined: Mon Jun 12, 2006 6:54 pm
Posts: 3
I just debugged the exact same problem. By renaming the column from version to xversion and rerunning Hibernate code generation I was able to circumvent the problem. This is clearly a bug in my opinion and should be entered on Jira.


Top
 Profile  
 
 Post subject: ClassCastException when existing table has "version&quo
PostPosted: Thu Jun 15, 2006 2:06 pm 
Newbie

Joined: Mon Jun 12, 2006 6:54 pm
Posts: 3
I just debugged the exact same problem. By renaming the column from version to xversion and rerunning Hibernate code generation I was able to circumvent the problem. This is clearly a bug in my opinion and should be entered on Jira.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 5:29 am 
Newbie

Joined: Fri Mar 23, 2007 5:13 am
Posts: 3
I've got the same problem with hibernate-3.2.2.ga.zip and a mysql database


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 10:37 pm 
Newbie

Joined: Tue Mar 27, 2007 12:19 pm
Posts: 1
I was getting the same error using Hibernate 3.2.4.ga and Hibernate tools 3.2.0.beta9a using a legacy Sybase database that I could not change the name of the column. Since we are not using the “vrsion” feature in Hibernate, to get around the problem I commented out the following lines in persistentclass.hbm.ftl.

<#-- version has to be done explicitly since Annotation's does not list version first -->
<#--<#if pojo.hasVersionProperty()>
<#assign property=clazz.getVersion()/>
<#include "${c2h.getTag(property)}.hbm.ftl"/>
</#if>-->


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