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.