-->
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: Hibernate / Tomcat / JNDI - the saga continues.
PostPosted: Tue Jan 18, 2005 6:49 am 
Newbie

Joined: Tue Jan 18, 2005 6:40 am
Posts: 1
Location: Perth, WA
Hibernate version:2+


Here are the 3 key parts to the error we get when trying to use Hibernate with Tomcats JNDI feature:

Cannot create JDBC driver of class '' for connect URL 'null'
Caused by: java.sql.SQLException: No suitable driver
net.sf.hibernate.exception.GenericJDBCException: Cannot open connection



Tomcats read only JNDI conetxt works just fine. The following code satisfied me in this regard:

<%
String success = null;
try {
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:/comp/env/jdbc/ora");
success = "yayyy";
System.out.println("Success: " + ds.toString());
}
catch (Exception e) {
success = "oh shit - here we go again";
}
%>

<%= success %>


Here is the relevant portion of sever.xml. To rule out a whole catagory of post responses, we have tried having the location of this file in both the web application's own context.xml and in the global server.xml.

<resource name="jdbc/ora" auth="container" type="javax.sql.DataSource">
<resourceParams>
<paramter>
<name>driverClassName</name>
<value>oracle.jdbc.OracleDriver</value>
</paramter>
<paramter>
<name>url</name>
<value>jdbc:oracle:thin:@localhost:1521:ORCL</value>
</paramter>
<paramter>
<name>username</name>
<value>store</value>
</paramter>
<paramter>
<name>password</name>
<value>store_password</value>
</paramter>
<paramter>
<name>maxActive</name>
<value>20</value>
</paramter>
<paramter>
<name>maxIdle</name>
<value>30000</value>
</paramter>
<paramter>
<name>maxWait</name>
<value>100</value>
</paramter>
</resourceParams>
</resource>

As you would expect, the relevant section of web.xml ammended with a few variations of the following (With and without 'sharable' etc):

<resource-ref>
<res-ref-name>jdbc/ora</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

Here is the hibernate.cfg. This has been tried with the session-factory name attribute removed and with various other combinations of elements - this should be all that is needed however.:

<session-factory name="java:comp/env/hibernate/SessionFactory">
<!-- properties java:/comp/env/-->
<property name="connection.datasource">java:/comp/env/jdbc/ora</property>
<property name="dialect">net.sf.hibernate.dialect.Oracle</property>
<property name="show_sql">false</property>

<!-- mapping files -->
<mapping resource="hiberTest/persisted/assessment.hbm.xml"/>
<mapping resource="hiberTest/persisted/testtaker.hbm.xml"/>
<mapping resource="hiberTest/persisted/testtakerAssessment.hbm.xml"/>

</session-factory>


There are no conflicts, typos, or clashing .properties files on the classpath, or anything in the world that should prevent Hibernate using our JNDI wired DataSource. I fully expect any and every response to reiterate something we have already tried, and tried with at tleast 2 tomcat versions on more than 4 different occasions in isolation and in combination with other suggestions. Pessimistic, I know. We said we would give the issue a month and then drop Hibernate for something that will work as we need it too - that gives us appox 3 days to sort it out. Its not looking good.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 02, 2005 6:48 pm 
Newbie

Joined: Fri Jan 14, 2005 2:53 pm
Posts: 7
We are running into the same problem.

Tomcat 5.5, Hibernate 2.1.7, and Oracle.

I've created a context.xml in the META-INF directory, rather than editing the global server.xml, but the JNDI entry is in the context under the expected name. (Used your test code to verify.)

It does look like something is wrong with the way we have the "connection.datasource" name in the hibernate.cfg.xml file, but it's matching all the examples/documentation I've seen.

Alternately, it's vaguely possible that it's not finding oracle.jdbc.driver.OracleDriver in the Tomcat/common/lib directory.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 05, 2005 12:58 pm 
Newbie

Joined: Mon Apr 11, 2005 4:55 am
Posts: 16
This answer comes late, but here is the solution for TomCat. Hope it will help someone.

You have to add a ResourceLink in your Context.xml, in order to let Hibernate using the global resource, witch is in read only mode.

Code:
<ResourceLink name="jdbc/ora" global="jdbc/ora"
      type="javax.sql.DataSource"/>


Here is the explaination from the book "Professional Apache Tomcat 5"

"The <ResourceLink> element refers to a previously configured JNDI resource (typically in the
<GlobalNamingResource> sub-element associated with a server), making these resources available to
all <Service>, <Host>, and <Context> components. This enables resources to be defined and shared
across servers or globally."


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.