This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Object Relational Mapping and the fly likes ClassCastException while building the sessionfactory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "ClassCastException while building the sessionfactory" Watch "ClassCastException while building the sessionfactory" New topic

ClassCastException while building the sessionfactory

chandrakanth boga
Ranch Hand

Joined: Mar 15, 2006
Posts: 49
Hello ..

I am getting ClassCastException when i start the jboss server.
i am using hibernate for creating session and etc..

The error in the console shows:--

07:43:21,265 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
07:43:21,265 INFO [NamingHelper] JNDI InitialContext properties:{}
07:43:21,281 INFO [STDOUT] [HR] Exception caught while calling l_hibCfg.buildSessionFactory()
07:43:21,296 INFO [STDOUT] java.lang.ClassCastException
07:43:21,296 INFO [STDOUT] at net.sf.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager(JNDIT
07:43:21,296 INFO [STDOUT] at net.sf.hibernate.transaction.JTATransactionFactory.configure(JTATransactionFactory.ja
07:43:21,312 INFO [STDOUT] at net.sf.hibernate.transaction.TransactionFactoryFactory.buildTransactionFactory(Transa
07:43:21,312 INFO [STDOUT] at net.sf.hibernate.cfg.SettingsFactory.buildSettings(
07:43:21,312 INFO [STDOUT] at net.sf.hibernate.cfg.Configuration.buildSettings(
07:43:21,328 INFO [STDOUT] at net.sf.hibernate.cfg.Configuration.buildSessionFactory(
07:43:21,328 INFO [STDOUT] at com.jnc.hibernate.HibernateRegistry.registerFactory(
07:43:21,343 INFO [STDOUT] at com.jnc.hibernate.HibernateRegistry.initializeRegistry(
07:43:21,343 INFO [STDOUT] at com.jnc.hibernate.HibernateRegistry.<init>(
07:43:21,343 INFO [STDOUT] at com.jnc.novell.director.impl.HibernateRegistryManager.resourceSetAvailable(HibernateR
07:43:21,343 INFO [STDOUT] at com.jnc.novell.director.impl.HibernateResourceListener$


I have been struggling since three days......
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10066

07:43:21,296 INFO [STDOUT] at net.sf.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager(JNDIT

Can you post the contents of the (or hibernate.cfg.xml depending on which one you are using).

[My Blog] [JavaRanch Journal]
chandrakanth boga
Ranch Hand

Joined: Mar 15, 2006
Posts: 49

<!-- *****************************************************************************************************
***************************************************************************************************** --> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "" > <hibernate-configuration>
<session-factory name="ust-model">
<!-- Database connection and transaction properties -->
<property name="connection.datasource">java:/JDBC/MIB</property>
<property name="transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>
<property name="transaction.manager_lookup_class">
<property name="dialect">net.sf.hibernate.dialect.Oracle9Dialect</property>

<!-- Additional configuration properties -->
<property name="show_sql">false</property>

<!-- WARNING: This causes great problems with the oracle driver, it doesn't return a valid rowcount must be FALSE with Oracle -->
<property name="jdbc.batch_versioned_data">false</property>

<!-- This property allows you to enable HQL query caches, using Query.setCacheable(true) and Query.setCacheRegion(name) for ehcache.xml config -->
<property name="cache.use_query_cache">true</property>

<!-- mapping files to be included with this session factory -->
<mapping resource="/hibernate/USTModel-USTDocumentLink.hbm.xml"/>
<mapping resource="/hibernate/USTModel-USTDossierEvent.hbm.xml"/>
<mapping resource="/hibernate/USTModel-USTDossierComment.hbm.xml"/>
<mapping resource="/hibernate/USTModel-USTDossierStatus.hbm.xml"/>
<mapping resource="/hibernate/USTModel-USTDossierScenario.hbm.xml"/>
<mapping resource="/hibernate/USTModel-USTDossierOrderItem.hbm.xml"/>
<mapping resource="/hibernate/USTModel-USTDossierScenarioFeature.hbm.xml"/>
<mapping resource="/hibernate/USTModel-USTDossierAbstractBlob.hbm.xml"/>
<mapping resource="/hibernate/USTModel-BlobPart.hbm.xml"/>
<mapping resource="/hibernate/USTModel-USTDossier.hbm.xml"/>
<mapping resource="/hibernate/USTModel-USTConversionFactor.hbm.xml"/>
<!-- //~pb: Issue #00368 -->
<mapping resource="/hibernate/USTModel-USTNewDiscussionsView.hbm.xml"/>
<mapping resource="/hibernate/USTModel-USTNewPrivateNotesView.hbm.xml"/>

Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10066

Which version of JBoss are you using? Also, have you packaged and jboss related jars (especially the jta related jars) in your application? Can you also post the some logs, that you see before the exception is thrown?
chandrakanth boga
Ranch Hand

Joined: Mar 15, 2006
Posts: 49
Hello Jai..

The jboss version is :-
JBoss [Zion] 4.0.2

Actually i could not see any jta.jar file in the application.....

You can see the console log file before exception :--


09:17:49,828 INFO [Server] JBoss (MX MicroKernel) [4.0.2 (build: CVSTag=JBoss_4_0_2 date=200505022023)] Started in 53s:141ms
09:17:56,515 INFO [STDOUT] ~~~~~~~~~~~~~~ number of session factories to be built -->2
09:17:56,640 INFO [Environment] Hibernate 2.1.8
09:17:56,656 INFO [Environment] not found
09:17:56,671 INFO [Environment] using CGLIB reflection optimizer
09:17:56,687 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling
09:17:56,718 INFO [Configuration] configuring from XML document
09:17:56,734 INFO [Configuration] Configured SessionFactory: ust-model
09:17:56,750 INFO [Configuration] Mapping resource: /hibernate/USTModel-USTDossierComment.hbm.xml
09:17:58,125 INFO [Binder] Mapping class: com.pms.ust.model.USTDossierComment -> UST_DOSSIER_COMMENT
09:17:58,625 INFO [Configuration] Mapping resource: /hibernate/USTModel-USTDossierScenario.hbm.xml
09:17:58,750 INFO [Binder] Mapping class: com.pms.ust.model.USTDossierScenario -> UST_QUOTE_SCENARIO
09:17:58,828 INFO [Configuration] Mapping resource: /hibernate/USTModel-USTDocumentLink.hbm.xml
09:17:58,937 INFO [Binder] Mapping class: com.pms.ust.model.USTDocumentLink -> UST_DOCUMENT_LINK
09:17:58,968 INFO [Configuration] Mapping resource: /hibernate/USTModel-USTDossierOrderItem.hbm.xml
09:17:59,062 INFO [Binder] Mapping class: com.pms.ust.model.USTDossierOrderItem -> UST_UPGRADELINE_CONTENT
09:17:59,078 INFO [Configuration] Mapping resource: /hibernate/USTModel-USTDossierStatus.hbm.xml
09:17:59,187 INFO [Binder] Mapping class: com.pms.ust.model.USTDossierStatus -> UST_DOSSIER_STATUS
09:17:59,218 INFO [Configuration] Mapping resource: /hibernate/USTModel-USTDossierAbstractBlob.hbm.xml
09:17:59,281 INFO [Binder] Mapping class: com.pms.ust.model.USTDossierAbstractBlob -> UST_DOSSIER_BLOBS
09:17:59,453 INFO [Binder] Mapping subclass: com.pms.ust.model.USTDossierSystemConfigBlob -> UST_DOSSIER_BLOBS
09:17:59,484 INFO [Binder] Mapping subclass: com.pms.ust.model.USTDossierQuoteOfferBlob -> UST_DOSSIER_BLOBS
09:17:59,500 INFO [Binder] Mapping subclass: com.pms.ust.model.USTDossierQuoteAgreementBlob -> UST_DOSSIER_BLOBS
09:17:59,515 INFO [Configuration] Mapping resource: /hibernate/USTModel-USTDossier.hbm.xml
09:17:59,640 INFO [Binder] Mapping class: com.pms.ust.model.USTDossier -> UST_DOSSIER
09:18:00,359 INFO [Configuration] Mapping resource: /hibernate/USTModel-USTNewDiscussionsView.hbm.xml
09:18:00,453 INFO [Binder] Mapping class: com.pms.ust.model.USTNewDiscussion -> UST_NEW_DISCUSSIONS_VIEW
09:18:00,484 INFO [Configuration] Mapping resource: /hibernate/USTModel-BlobPart.hbm.xml
09:18:00,578 INFO [Binder] Mapping class: com.pms.ust.model.BlobPart -> UST_BLOB_PARTS
09:18:00,609 INFO [Configuration] Mapping resource: /hibernate/USTModel-USTConversionFactor.hbm.xml
09:18:00,703 INFO [Binder] Mapping class: com.pms.ust.model.USTConversionFactor -> UST_CURRENCY_CONV_FACTORS
09:18:00,718 INFO [Configuration] Mapping resource: /hibernate/USTModel-USTDossierEvent.hbm.xml
09:18:00,812 INFO [Binder] Mapping class: com.pms.ust.model.USTDossierEvent -> UST_DOSSIER_EVENT
09:18:00,843 INFO [Configuration] Mapping resource: /hibernate/USTModel-USTDossierScenarioFeature.hbm.xml
09:18:00,906 INFO [Binder] Mapping class: com.pms.ust.model.USTDossierScenarioFeature -> UST_SCENARIO_DETAILS
09:18:00,921 INFO [Configuration] Mapping resource: /hibernate/USTModel-USTNewPrivateNotesView.hbm.xml
09:18:01,031 INFO [Binder] Mapping class: com.pms.ust.model.USTNewPrivateNote -> UST_NEW_PRIVATENOTES_VIEW
09:18:01,046 INFO [Configuration] processing one-to-many association mappings
09:18:01,062 INFO [Binder] Mapping collection: com.pms.ust.model.USTDossierScenario.features -> UST_SCENARIO_DETAILS
09:18:01,078 INFO [Binder] Mapping collection: com.pms.ust.model.USTDossierStatus.dossiers -> UST_DOSSIER
09:18:01,093 INFO [Binder] Mapping collection: com.pms.ust.model.USTDossierAbstractBlob.m_setBlobs -> UST_BLOB_PARTS
09:18:01,109 INFO [Binder] Mapping collection: com.pms.ust.model.USTDossier.quotation.scenarioos -> UST_QUOTE_SCENARIO
09:18:01,125 INFO [Binder] Mapping collection: com.pms.ust.model.USTDossier.m_csEvents -> UST_DOSSIER_EVENT
09:18:01,156 INFO [Binder] Mapping collection: com.pms.ust.model.USTDossier.m_csComments -> UST_DOSSIER_COMMENT
09:18:01,171 INFO [Binder] Mapping collection: com.pms.ust.model.USTDossier.m_csOrderItems -> UST_UPGRADELINE_CONTENT
09:18:01,187 INFO [Binder] Mapping collection: com.pms.ust.model.USTDossier.m_csSysConfigBlob -> UST_DOSSIER_BLOBS
09:18:01,203 INFO [Binder] Mapping collection: com.pms.ust.model.USTDossier.m_csQuoteOfferBlob -> UST_DOSSIER_BLOBS
09:18:01,218 INFO [Binder] Mapping collection: com.pms.ust.model.USTDossier.m_csQuoteAgreeBlob -> UST_DOSSIER_BLOBS
09:18:01,234 INFO [Configuration] processing one-to-one association property references
09:18:01,250 INFO [Configuration] processing foreign key constraints
09:18:01,375 INFO [Dialect] Using dialect: net.sf.hibernate.dialect.Oracle9Dialect
09:18:01,421 INFO [SettingsFactory] Use outer join fetching: true
09:18:01,468 INFO [NamingHelper] JNDI InitialContext properties:{}
09:18:01,484 INFO [DatasourceConnectionProvider] Using datasource: java:/JDBC/MIB
09:18:01,500 INFO [TransactionFactoryFactory] Transaction strategy: net.sf.hibernate.transaction.JTATransactionFactory
09:18:01,546 INFO [NamingHelper] JNDI InitialContext properties:{}
09:18:01,562 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: net.sf.hibernate.transaction.JBossTransactionManagerLookup
09:18:01,593 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
09:18:01,609 INFO [NamingHelper] JNDI InitialContext properties:{}

Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10066

Logs look good to me. Please follow the steps below and post the output here:

- From the command prompt, go to %JBOSS_HOME%/server/default/deploy folder
- Run the following command

jar -tf myApp.ear

where myApp.ear is your application file name. Replace it appropriately with your application's file name and extension.

This will show the contents of the application. Post the contents here. That might give us a hint.
chandrakanth boga
Ranch Hand

Joined: Mar 15, 2006
Posts: 49
Hi jai.....

I got the solution....
I removed hibernate2.jar file from this directory:-

I got to know about this after reading this thread:--

Thanks for your support...

But i did not know the reason technicaly....
could you please explain me in detail..
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10066

Originally posted by chandrakanth boga:
But i did not know the reason technicaly....
could you please explain me in detail..

A class is uniquely identified by its packagename, classname as well as the classloader which loaded the class. In this specific case, the classes related to Hibernate were present in 2 different jars in the classpath. One hibernate jar was present (by default) in the %JBOSS_HOME%/server/default/lib and the other jar (as you mentioned) was present in your applications lib folder. The jar present in the %JBOSS_HOME%/server/default/lib folder will be loaded by JBoss' system wide classloader. The jar present in your application will be loaded by application specific classloader. This meant that 2 different classloaders were loading the same hibernate classes. As a result, whenever there was a type casting going on in the code, hibernate classes loaded from one classloader were being casted to classes loaded through a different classloader. Although the classname and the packagename matched, the classloaders differed, resulting in the ClassCastException.

For more about how JBoss Classloaders work, have a look at:


chandrakanth boga
Ranch Hand

Joined: Mar 15, 2006
Posts: 49
Hello Jai..

Thats an exceptional Explanation.
Thanks for the detail explanation.

I agree. Here's the link:
subject: ClassCastException while building the sessionfactory