Hello,
I have 2 problems:
1. I am having a problem integrating Websphere 5.1 with Hibernate. Specifically, I am running into problems using JNDI for my datasource. I am getting a intialcontextfactory error. When I try to specify the Websphere initialcontextfactory, it says it can't find the class. When I take out the intialcontextfactory, it says I need to specify one.
2. My other dilemma is how to run my junit tests that I have been using outside the container with a regular Datasource connection. Now that I am using the JNDI datasource, do I have any way of running my junit tests with hibernate OUTSIDE the container?
Hibernate version:
3.1.3
Mapping documents:
Code:
<property name="hibernate.cglib.use_reflection_optimizer">false</property>
<property name="hibernate.connection.datasource">jdbc/Db</property>
<property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WebSphereTransactionManagerLookup</property>
then i specify the initalcontextfactory:
Code:
<property name="hibernate.cglib.use_reflection_optimizer">false</property>
<property name="hibernate.connection.datasource">jdbc/TivaDb</property>
<property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="jndi.url">t3://localhost:2809/</property>
<property name="jndi.class">com.ibm.ejs.ns.jndi.CNInitialContextFactory</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WebSphereTransactionManagerLookup</property>
Code between sessionFactory.openSession() and session.close():Code:
URL url = HibernateUtil.class.getResource("hibernate.cfg.xml");
Configuration cfg = new Configuration();
sessionFactory = cfg.configure(url).buildSessionFactory();
Full stack trace of any exception that occurs:Code:
[5/9/06 13:02:01:436 EDT] 1168e099 SystemErr R May 9, 2006 1:02:01 PM org.hibernate.util.NamingHelper getInitialContext
INFO: JNDI InitialContext properties:{}
[5/9/06 13:02:01:451 EDT] 1168e099 SystemErr R May 9, 2006 1:02:01 PM org.hibernate.connection.DatasourceConnectionProvider configure
SEVERE: Could not find datasource: jdbc/Db
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:653)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:257)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:294)
at javax.naming.InitialContext.lookup(InitialContext.java:361)
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:366)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:60)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1881)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1174)
when I am specifying the initialcontextfactory:
Code:
[5/9/06 13:18:24:179 EDT] 17ef62bf SystemErr R May 9, 2006 1:18:24 PM org.hibernate.util.NamingHelper getInitialContext
INFO: JNDI InitialContext properties:{java.naming.provider.url=t3://localhost:2809/, java.naming.factory.initial=com.ibm.ejs.ns.jndi.CNInitialContextFactory}
[5/9/06 13:18:24:195 EDT] 17ef62bf SystemErr R May 9, 2006 1:18:24 PM org.hibernate.util.NamingHelper getInitialContext
SEVERE: Could not obtain initial context
javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.ejs.ns.jndi.CNInitialContextFactory. Root exception is java.lang.ClassNotFoundException: com.ibm.ejs.ns.jndi.CNInitialContextFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java(Compiled Code))
at java.lang.ClassLoader.loadClass(ClassLoader.java(Compiled Code))
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java(Compiled Code))
at java.lang.ClassLoader.loadClass(ClassLoader.java(Compiled Code))
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:260)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:60)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:257)
at javax.naming.InitialContext.init(InitialContext.java:233)
at javax.naming.InitialContext.<init>(InitialContext.java:209)
at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:366)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:60)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1881)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1174)
Name and version of the database you are using:
DB2 UDB 8.1
The generated SQL (show_sql=true):
n/a
Debug level Hibernate log excerpt:
n/a