• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Hibernate not finding Oracle driver - despite straight JDBC working

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
tomcat 5 / hibernate 2 / oracle 10g

- Could not obtain connection metadata
org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'


Been at this a few hours now - just cant get hibernate to work. I have my driver in the right place (web-inf/lib and also tried common/lib too), my config file and properties files all by the book. My tomcat JNDI resource is all set up right (its working with DBCP in its own right, so driver is working in a non hibernate situation)

I have changed the sqlDialect property around a couple of time too - in case it had issue with the generic Oracle dialect and preffered the Oracle9 dialect.

No luck - about to give up on Hibernate altogether (I am yet to see it work!)
This issue seems to be suggesting my tomcat JNDI set up is incorrect -but its not! Its working just fine using straight JDBC lookups.

Any help at all would be appreciated - even sympathy would do.

Andles
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I reckon your hibernate.connection.url property is missing. Double check the code where you configure your SessionFactory - typically unless you specifically set the properties to come from elsewhere Hibernate will look for them from the file hibernate.properties. If Hibernate can't find that file (which needs to be in your classpath) or if you've not set that property this might be the cause of you problems.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure I have a direct answer, but this gives me a clue.

for connect URL 'null'



As you know, in order for JDBC to connect to a database it needs to know where the database is. If you don't give it a URL, then it has no idea where to look.

Here is where I don't have a direct answer, I am sure their is a config type file for you to put the URL for the database, I thought it would be in the declaration of the DataSource. Maybe the DataSource isn't set up in the hibernate configuration.

Good Luck, and please don't give up on Hibernate because of this.

Mark
 
Andles Jurgen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my config, which is in my classpath.



<hibernate-configuration>

<session-factory>

<property name="connection.datasource">java:comp/env/jdbc/webApps</property>
<property name="show_sql">true</property>
<property name="dialect">net.sf.hibernate.dialect.OracleDialect</property>
<property name="connection.url">jdbc racle:thin:@localhost:1521 RCL</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.username">store</property>
<property name="connection.password">******</property>

<property name="transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactory</property>


<!-- Mapping files -->
<mapping resource="Person.hbm.xml"/>

</session-factory>

</hibernate-configuration>

The only other thing I should add is that I am using Tomcat via JBuilder and that it is running in embedded mode -that should have nothing to do with the price of cheese in china, thought I should mention it anyway.

I have made sure I have DBCP, my Oracle driver etc in the tomcat global classpath (common/lib) and have tried it just in the context classpath.

Thanks for your help so far guys, really appreciated.
 
Andles Jurgen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry - heres my resource declareation in server.xml and the relavant web.xml

SERVER.XML

<resource name="jdbc/webApps" auth="container" type="javax.sql.DataSource">
<resourceParams>

<paramter>
<name>driverClassName</name>
<value>oracle.jdbc.OracleDriver</value>
</paramter>

<paramter>
<name>url</name>
<value>jdbc racle:thin:@localhost:1521 RCL</value>
</paramter>

<paramter>
<name>store</name>
<value></value>
</paramter>

<paramter>
<name>store_password</name>
<value></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>


WEB.XML


<res-ref-name>jdbc/webApps</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
 
Andles Jurgen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just an update:
I can get it going now using a Driver_class property, but NOT with a datasource property. I want to use my datasource set up though.

I have to say. the documentation for this stuff is very misleading and not at all clear. Even reading 'professional Hibernate" is very weak on set up. (Actually that whole book is a bit of a joke -there isn't an ounce of source code in there that would comiple and th etypos and grammar is the worst I have ever seen - and I have read a LOT of tech books!)

Anyway, I am starting to see a few places I may be going wrong - for example having a driver_class AND a datasource property was likely not a clever thing to do!

Getting closer....
 
Andles Jurgen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Talking to myself a bit now, I know:

I have managed to get Hibernate working, but only using the driver class property. I want it to work with my tomcat defined JNDI datasource and I am expecting something like the following to work:

hibernate.connection.datasource = java:comp/env/jdbc/webApps
hibernate.connection.username = fedup
hibernate.connection.password = *****

My JNDI is set up correctly, I can connect using other hibernate options (non jndi), I have tried many configurations over the last 2 days, and I can only afford to plod on one more day before switching over to toplink (with our jdeveloper/oracle license) as I have had success withing ten minutes with using this product.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, looking at Hibernate In Action, I noticed this

you have this for the datasource.

java:comp/env/jdbc/webApps



In the book they would have a "/" before comp

Like

java:/comp/env/jdbc/webApps

Since the DataSource stores all the user/password stuff, you should not need to use that.

Mark
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I run into a similar problem every time I am setting up a Tomcat 5 web app from scratch, and it always stumps me for a few hours because I never remember what I did to solve the issue... hopefully next time my googling will hit this post...

So, allow me to document this for posterity and myself

I suspect this problem only happens when one is deploying unpacked directories. The issue is that you're probably using the Ant manager tasks, and the deployment task does not pick up your context.xml and copy it properly to tomcat's conf/Catalina/localhost. You can verify this by checking the directory in question -- if your ${appname}.xml file just has an empty Context element instead of your datasource definitions and parameters (you've got them there, don't you?), then you've been bit by this.

Either copy the context.xml manually into the conf/Catalina/localhost directory of your tomcat installation, or use the "config" parameter in the deploy task to point to the context.xml of your exploded war directory. HTH.

The error messages in this case are particularly unhelpful, in the style of ...



On the other hand, if your raw JDBC works... it might not be this.
[ January 14, 2005: Message edited by: Eero Nevalainen ]
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I suppose you're off and runnnig with Toplink now, but in case someone hits upon this, here's my configs. I'm using Tomcat 5, Hibernate 2 and DBCP with a JNDI DataSource.I'm using Spring to configure Hibernate, but the only interesting bit is the DataSource.Notice that the only thing I specify is the JNDI name -- not driver class, URL, username or password. Perhaps those are confusing Hibernate, though that seems unlikely. BTW, the SessionFactory bean has the other configs you showed (show_sql, dialect, mappings, etc).

I noticed one other thing that seemed odd, but then since JDBC works perhaps it's not a problem:Shouldn't the names be "username" and "password"? I suspect it's a typo from removing the password since your username seems to be "store" in your Hibernate config.
 
Andles Jurgen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, just a typo in my post - the file iteslf is correct.

I am still having no luck getting Hibernate to see the Tomcat configured JNDI resource. Yet, the DataSource works as expected using straight JDBC in code.

You are right, the username and passowrd stuf should all be irrelavant as this is part of the DataSource config - I added it and un-added it and did god knows what else in an attempt to get it to work - NO LUCK AT ALL!

I have reverted back to using a configured Driver instead of a Datasource, but this is just not good enough. Its been a few weeks now since we have been evaluating Hibernate and nobody here is happy with this issue or the lack of a solution - so we will very likely end up using TopLink via JDeveloper in production.

Perhaps Hibernate is just not ready for real apps just yet - I see so many posts from people who simply cannot get the thing to even work!
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Perhaps Hibernate is just not ready for real apps just yet - I see so many posts from people who simply cannot get the thing to even work!


I'll have to take umbrage at this comment. Not only is it ready for real apps (and has been for some time) it is being used in deployed applications and has been included in JBoss. I know having to configure things through lots of XML files can be frustrating, but please don't confuse configuration errors with deficiencies in a product.

Try using it with a DataSourceConnectionProvider, rather than DBCP (which is being deprecated in v3.0).
[ January 18, 2005: Message edited by: Paul Sturrock ]
 
Andles Jurgen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Been there, done that. No luck whatsoever.

re: umbrage

Not sure what 'umbrage' actually means. But I guess you took offense (umbrage?) to my 'real apps' comment. I didn't mean that quite the way it sounded - though I must confess, I have very little idea about Hibernates popularity or how widespread it is - I guess I am influenced a little by some commercial ORM tools we have used. Certainly didn't mean to umbrage you.

At the end of the day though, when a product takes near a month to get it working, and it still doesn't work the way you were told it would - yes, its more than just a little frustrating. Yes, it is open source, but it has certainly cost us in very real austrlain dollars so far. And got us practically nowhere that we needed to be.
 
Andles Jurgen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 racle:thin:@localhost:1521 RCL</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.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


But I guess you took offense (umbrage?) to my 'real apps' comment


No need to worry Andles - I'm not personally offended, I am just aware of the effect comments like this have on people's perception of a product. And I hope I'm not offending you to suggest your view of the product is very much coloured by the specific problems you are experiencing, rather than a general failing in the product itself?

One thing I'd very much recommend is get the Hibernate source for whichever version you are using and step through it in your debugger. Its easier (and quicker) than trying to make educated guesses in your configuration files.

(BTW: you are right umbrage is a slightly quaint word basically meaning offense)
[ January 18, 2005: Message edited by: Paul Sturrock ]
 
Andles Jurgen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
re:
One thing I'd very much recommend is get the Hibernate source for whichever version you are using and step through it in your debugger.

Been there, done that. No luck whatsoever. Seriously, this has gottent o the the point where we should have just went commericial (and will likely still end up doing) as it is just not behaving as we expected it too.

It certainly seems to be a recurring problem and there seems to be quite a few folk out there that have given up and/or have yet to resolve the issue - so I do not believe it is an issue specific to our environment. (we have tried several of those too)


Technical competence is not the issue here either. We have spiked several others, just to see if we could get them going - sure enough, no dramas at all. TopLink was a pest, a good 4 hours to get that happening, and a few others were a little tricky without a visist to the appropriate web site or user community, but they worked within 1 day.


I would love to know how many people just gave up on Hibernate but never bothered to let us all know why. I'd bet this relatively simple task of getting hibernate to use your chosen database access/connection could have had something to do with quite a few of them? We even considered at one point going prod without a JNDI DataSource, how many others just gave up in this fashion too?


The fact remains - I like Hibernate for so many reasons. If somebody could jus tell me why we cant for the life of us get it to work properly with a DataSource or simply say "Hey, it doesn't work with a Tomcat DataSource" - life would be much better!
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Been there, done that. No luck whatsoever.


Interesting. And very odd. You might consider giving JBoss support a call - if your project has any money to do so. Their support is very good, and you will probably get one of the Hibernate developer's looking at this for you.

All I can say (and this may well be very frustrating to hear ) is our experience was Hibernate was the easiest of the ORMs we looked at to get going with!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had this same exact error message with Tomcat 4.1.31/Spring 1.1.1/Oracle 10g. I was moving from OC4J to Tomcat so I knew my app worked in another env and it was server specific and not Spring/Hibernate specific.

What solved the error (listed below) for me was following a post on a Tomcat forum -- I can't find it so credit is due to someone else out there.

Place a context around your jndi resource definitions in the tomcat server.xml


Listed is the error message I was getting.


I also have another application that uses Spring with Hibernate running well in the Tomcat environment. HTH.

Monica
[ February 07, 2005: Message edited by: Monica Crawford ]
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Here is what I had to in TomCat 5.5/Hibernate 2.1.

I used Postgres, create a database called catdb and added a user quickstart (password is secret). Made sure the user had proper authorization for the "CAT" table.

server.xml (the tags need to be inside the <host> element):

<Context path="/quickstart" docBase="quickstart" debug="1" >
<Resource name="jdbc/quickstart" auth="Container"
type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
url="jdbc ostgresql://127.0.0.1:5432/catdb"
username="quickstart" password="secret" maxActive="10" maxIdle="100" maxWait="3000"/>
</Context>

web.xml:
<web-app>

<display-name>Hibernate Quick Start</display-name>
<description>
Hibernate Quick Start.
</description>

<!-- Define servlets that are included in the example application -->

<servlet>
<servlet-name>CatServlet</servlet-name>
<servlet-class>net.sf.hibernate.examples.quickstart.servlet.CatServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>CatServlet</servlet-name>
<url-pattern>/cat</url-pattern>
</servlet-mapping>

<resource-ref>
<description>postgreSQL Cat Datasource</description>
<res-ref-name>jdbc/quickstart</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>


</web-app>

hibernate.cfg.xml:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>

<session-factory>

<property name="connection.datasource">java:comp/env/jdbc/quickstart</property>
<property name="show_sql">false</property>
<property name="dialect">net.sf.hibernate.dialect.PostgreSQLDialect</property>

<!-- Mapping files -->
<mapping resource="Cat.hbm.xml"/>

</session-factory>

</hibernate-configuration>

Of course for Oracle the values are a little bit different but the XML elements above are the same.

Good luck
reply
    Bookmark Topic Watch Topic
  • New Topic