-->
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 Configuration in Tomcat 5.5 for use in Hibernate
PostPosted: Tue Apr 20, 2010 10:41 am 
Newbie

Joined: Tue Apr 20, 2010 10:30 am
Posts: 2
Hi All,
I am not sure whether the same problem has been discussed before or not.
I am facing one problem in configuring JNDI entry in a sinple Web Apps which is using Tomcat 5.5

Specification i am using: Hibernate 3.0
Tomcat 5.5

Problem Description:

I have following entries in Tomcat's server.xml:

<Resource driverClassName="oracle.jdbc.driver.OracleDriver" logAbandoned="true" maxActive="4" maxIdle="2" maxWait="5000" name="jdbc/DB2DataSource" password="password" removeAbandoned="true" removeAbandonedTimeout="55" type="javax.sql.DataSource" url="jdbc:oracle:thin:@x.x.x.x:1521:dbname" username="user"/>


Entries in hibernate.cfg.xml is:

<hibernate-configuration>
<session-factory name="java:hibernate/SessionFactory">
<property name="connection.datasource">jdbc/DB2DataSource</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<!-- Mapping files -->
<mapping resource="sample.hbm.xml"/>
</session-factory>
</hibernate-configuration>

When I am running my application i am getting the following exception:

SEVERE: Could not find datasource: jdbc/DB2DataSource
Throwable occurred: javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
at javax.naming.InitialContext.lookup(Unknown Source)
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:1859)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1152)
at com.safmarine.fact.servlet.CheckVendorDetail.doPost(CheckVendorDetail.java:35)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)



I googled a lot and found that I need to use java:/comp/env/jdbc/DB2DataSource as connection.datasource in hibernate.cfg file. That means it looks like :

<hibernate-configuration>
<session-factory name="java:hibernate/SessionFactory">
<property name="connection.datasource">jdbc/DB2DataSource</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<!-- Mapping files -->
<mapping resource="sample.hbm.xml"/>
</session-factory>
</hibernate-configuration>

And still I am getting the exception like below:

SEVERE: Could not find datasource: java:/comp/env/jdbc/DB2DataSource
Throwable occurred: javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
at javax.naming.InitialContext.lookup(Unknown Source)
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:1859)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1152)





Can somebody please help me. How can i define the JNDI entry and run mmy application? Its very urgent. Please respond. I will be highly obliged.

Thanks in advance.

Cheers,
Swarup


Top
 Profile  
 
 Post subject: Re: JNDI Configuration in Tomcat 5.5 for use in Hibernate
PostPosted: Wed Apr 21, 2010 3:08 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Hi Swarup,

take a look at thread
viewtopic.php?f=1&t=1003866
mavericjr there finally did successfully use a datasource defined in tomcat,
using context.xml and web.xml


Top
 Profile  
 
 Post subject: Re: JNDI Configuration in Tomcat 5.5 for use in Hibernate
PostPosted: Wed Apr 21, 2010 2:54 pm 
Newbie

Joined: Wed Apr 21, 2010 2:45 pm
Posts: 1
Hi swarup2010,

I had the same error. You're just missing "java:/comp/env/" defore the name of your datasource.

I found the probleme while checking this page:
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html#configuration-xmlconfig

Your config should be like this:
Code:
<hibernate-configuration>
   <session-factory name="java:hibernate/SessionFactory">
      <property name="connection.datasource">java:/comp/env/jdbc/DB2DataSource</property>
      <property name="show_sql">true</property>
      <property name="dialect">org.hibernate.dialect.OracleDialect</property>
      <!-- Mapping files -->
      <mapping resource="sample.hbm.xml"/>
   </session-factory>
</hibernate-configuration>


Hope this helps,

Matt


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.