-->
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: JNDI vs. regular Datasource
PostPosted: Tue May 09, 2006 1:23 pm 
Newbie

Joined: Fri Jan 06, 2006 5:29 pm
Posts: 16
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 3:36 am 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
Quote:
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?


You can supply a different hibernate.cfg.xml which
specifies the DB connection via JDBC. e.g.:

Code:
        <property name="dialect">org.hibernate.dialect.DB2Dialect</property>
        <property name="hibernate.default_schema">dbo</property>
        <property name="connection.driver_class">COM.ibm.db2.jdbc.app.DB2Driver</property>
        <property name="connection.username">user</property>
        <property name="connection.password">passwort</property>
        <property name="connection.url">jdbc:db2:dbtest</property>


You certainly can not test websphere related problems with this.
But at least this should work for you business logic tests.

_________________
dont forget to rate !


Top
 Profile  
 
 Post subject: Thread outside container?
PostPosted: Wed May 10, 2006 8:19 am 
Newbie

Joined: Fri Jan 06, 2006 5:29 pm
Posts: 16
1. I think I might have isolated the issue for the intialcontextfactory. We are using JIntegra for COM to access java POJOs from VB. I have a listener servlet that is called on websphere startup, which kicks off a thread that initializes the JIntegra piece. For some reason, that thread is not seeing the JNDI stuff, or the classpath that websphere sees. It is probably a classpath issue ..... any suggestion would be helpful.

2. I have solved this using cactus.


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.