-->
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: WebSphere DataSource FATAL Errors. ClassCastException.
PostPosted: Wed Mar 17, 2004 10:04 pm 
Newbie

Joined: Wed Mar 17, 2004 3:33 pm
Posts: 5
Location: Florida, USA
Hi, I am trying to access websphere's datasource using Hibernate. I have been trying all different possibilities to fix this problem. I have fixed quite a bunch of problems during this process but now stuck with ClassCast Exception. (FATAL DatasourceConnectionProvider:47 - Could not find datasource: jdbc/ds1
java.lang.ClassCastException: javax.naming.Reference)

So, decided to take help from Hibernate experts. Please help as I am stuck with this for the past couple of days.

I do not see a problem with the datasource as I am able to access it using a JNDI lookup through a servlet.

I am able to access the following:
Hibernate --> DB2
Servlet --> WebSphere DataSource --> DB2

I am NOT able to..
Hibernate --> WebSphere DataSource --> Database.

Here is my environment:

Hibernate 2.1.2
WebSphere Platform 5.0 [BASE 5.0.2 ptf2M0325.01]
DB2 7.1.0
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1)
Classic VM (build 1.3.1, J2RE 1.3.1 IBM Windows 32 build cn131-20030711a (JIT enabled: jitc))

Here is the log/error info:
========================================================================
20:07:05,776 INFO Environment:462 - Hibernate 2.1.2
20:07:05,786 INFO Environment:496 - loaded properties from resource hibernate.properties: {hibernate.connection.password=prettybear, hibernate.jndi.class=com.ibm.websphere.naming.WsnInitialContextFactory, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.show_sql=true, hibernate.proxool.pool_alias=pool1, hibernate.jdbc.batch_size=0, hibernate.connection.datasource=jdbc/ds1, hibernate.transaction.manager_lookup_class=net.sf.hibernate.transaction.WebSphereTransactionManagerLookup, hibernate.jndi.url=iiop://localhost:2809, hibernate.cache.use_query_cache=true, hibernate.jdbc.use_streams_for_binary=true, hibernate.max_fetch_depth=1, hibernate.connection.pool_size=1, hibernate.connection.username=db2admin, hibernate.connection.driver_class=COM.ibm.db2.jdbc.app.DB2Driver, hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.DB2Dialect}
20:07:05,796 INFO Environment:518 - using java.io streams to persist binary types
20:07:05,796 INFO Environment:519 - using CGLIB reflection optimizer
20:07:05,806 INFO Environment:530 - JVM does not support Statement.getGeneratedKeys()
20:07:05,806 INFO Environment:541 - JVM does not support LinkedHasMap, LinkedHashSet - ordered maps and sets disabled
20:07:05,806 INFO Environment:544 - using workaround for JVM bug in java.sql.Timestamp
20:07:05,816 INFO Configuration:329 - Mapping resource: com/ibm/sastrack/domain/Country.hbm.xml
20:07:06,517 INFO Binder:229 - Mapping class: com.ibm.sastrack.domain.Country -> country
20:07:06,647 INFO Configuration:595 - processing one-to-many association mappings
20:07:06,647 INFO Configuration:604 - processing one-to-one association property references
20:07:06,647 INFO Configuration:629 - processing foreign key constraints
20:07:06,677 INFO Dialect:82 - Using dialect: net.sf.hibernate.dialect.DB2Dialect
20:07:06,717 INFO SettingsFactory:58 - Maximim outer join fetch depth: 1
20:07:06,717 INFO SettingsFactory:62 - Use outer join fetching: true
20:07:06,727 INFO NamingHelper:26 - JNDI InitialContext properties:{java.naming.provider.url=iiop://localhost:2809, java.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory}
20:07:13,156 FATAL DatasourceConnectionProvider:47 - Could not find datasource: jdbc/ds1
java.lang.ClassCastException: javax.naming.Reference
at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:44)
at net.sf.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:83)
at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:64)
at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1119)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:748)
at com.ibm.sastrack.domain.CountryTest.getCountry(CountryTest.java:21)
at com.ibm.sastrack.domain.CountryTest.main(CountryTest.java:42)
java.lang.NullPointerException
at com.ibm.sastrack.domain.CountryTest.getCountry(CountryTest.java:34)
at com.ibm.sastrack.domain.CountryTest.main(CountryTest.java:42)

============================================

hibernate.properties
=============================================
hibernate.query.substitutions true 1, false 0, yes 'Y', no 'N'

hibernate.connection.datasource jdbc/ds1
hibernate.connection.username db2admin
hibernate.connection.password prettybear

hibernate.dialect net.sf.hibernate.dialect.DB2Dialect
hibernate.connection.driver_class COM.ibm.db2.jdbc.app.DB2Driver


hibernate.connection.pool_size 1
hibernate.proxool.pool_alias pool1
hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.WebSphereTransactionManagerLookup
hibernate.show_sql true
hibernate.jdbc.batch_size 0
hibernate.jdbc.use_streams_for_binary true
hibernate.max_fetch_depth 1
hibernate.cache.use_query_cache true
hibernate.cache.provider_class net.sf.hibernate.cache.HashtableCacheProvider


hibernate.jndi.class com.ibm.websphere.naming.WsnInitialContextFactory
hibernate.jndi.url iiop://localhost:2809
================================================

JAR Files being used in the classpath.
================================================
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="var" path="Hibernate2" sourcepath="Hibernate_Source"/>
<classpathentry kind="var" path="HibernateCGILIB"/>
<classpathentry kind="var" path="HibernateCollections"/>
<classpathentry kind="var" path="HibernateDOM"/>
<classpathentry kind="var" path="HibernateJTA"/>
<classpathentry kind="var" path="HibernateLang"/>
<classpathentry kind="var" path="HibernateLog"/>
<classpathentry kind="var" path="HibernateLogging"/>
<classpathentry kind="var" path="HibernateODMG"/>
<classpathentry kind="var" path="HibernateXALAN"/>
<classpathentry kind="var" path="HibernateXERCES"/>
<classpathentry kind="var" path="HibernateXML"/>
<classpathentry kind="var" path="JRE_LIB"/>
<classpathentry kind="lib" path="C:/Program Files/IBM/WebSphere Studio/Application Developer/v5.1/runtimes/base_v5/lib/j2ee.jar"/>
<classpathentry kind="var" path="JUNIT"/>
<classpathentry kind="var" path="DB2JAVA"/>
<classpathentry kind="lib" path="C:/Program Files/IBM/WebSphere Studio/Application Developer/v5.1/runtimes/base_v5/lib/namingserver.jar"/>
<classpathentry kind="lib" path="C:/Program Files/IBM/WebSphere Studio/Application Developer/v5.1/runtimes/base_v5/lib/namingclient.jar"/>
<classpathentry kind="lib" path="C:/Program Files/IBM/WebSphere Studio/Application Developer/v5.1/runtimes/base_v5/lib/naming.jar"/>
<classpathentry kind="output" path="build"/>
</classpath>

================================================
Above mentioned Variables:
JRE_LIB = rt.jar in Websphere's base_v5/java/jre directory.
DB2JAVA = db2java.zip
JUNIT = junit.jar
variables staring with HIBERNATE, For example:
HibernateJTA = jta.jar in hibernate lib directory.
etc.,

Here is the piece of code that I am using...
=================================================
private void getCountry() throws Exception {
try {
cfg = new Configuration().addClass(Country.class);
factory = cfg.buildSessionFactory();

session = factory.openSession();
Country country = new Country();

country = (Country)session.get(Country.class, new Integer(209));

System.out.println(country.toString());
} catch (Exception e) {
throw e;

} finally {
session.close();
}
}
==================================================

Please let me know if you need more info.

Your help is appreciated.

_________________
Regards,
-Vikranth


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 18, 2004 8:34 am 
Regular
Regular

Joined: Mon Nov 24, 2003 6:36 pm
Posts: 105
Hi,
When you say hib-websphere datasource, do you mean you are running a unit test outside of the webapp... from wsad?

My web projects in wsad don't explicitly have the naming* jars that are on your classpath- only j2ee.jar, servletevent.jar, iivjejb35.jar, runtime.jar, and the hibernate libs.

Are you using the "websphere" jvm, or the default eclipse jvm (if you are running a unit test), ?

It might help to attach the hibernate source to the jar, so you can step in , and see where the cast fails.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 18, 2004 11:22 am 
Newbie

Joined: Wed Mar 17, 2004 3:33 pm
Posts: 5
Location: Florida, USA
Hibernate --> WebSphere Datasource --> DB2

I am using a Java Project inside WSAD. I have a simple Java Application with a main method that is calling the above mentioned method to get Hibernate Session Factory.

If I dont use websphere's lib naming* jars, I am getting different Errors such as

"ERROR NamingHelper:33 - Could not obtain initial context
javax.naming.ConfigurationException: The property com.ibm.ws.naming.wsn.factory.initial is not set. The most likely cause is that the jar which contains the file com/ibm/websphere/naming/jndiprovider.properties cannot be found by the class loader.
at com.ibm.websphere.naming.WsnInitialContextFactory.init_implClassCtor(WsnInitialContextFactory.java:190)
at com.ibm.websphere.naming.WsnInitialContextFactory.getInitialContext(WsnInitialContextFactory.java:108)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:255)
at javax.naming.InitialContext.init(InitialContext.java:231)
at javax.naming.InitialContext.<init>(InitialContext.java:207)
at net.sf.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)"

I am using Webspheres JVM to run Java Application.

I tried attaching Hibernate src code to debug but it was looking for more source files such as Collections src jar etc... This was the stage when I decided to post the question in the forum for help.

Thanks for your time.

_________________
Regards,
-Vikranth


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.