-->
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.  [ 12 posts ] 
Author Message
 Post subject: How to run the Hibernate "Cat" QuickStart example
PostPosted: Wed Oct 22, 2003 9:56 pm 
Newbie

Joined: Tue Oct 21, 2003 11:41 am
Posts: 11
Hi,

I am trying to run the "Cat" Quickstart example with TomCat 4.1.27.

I get this exception:
<from browser>
javax.servlet.ServletException: Could not find datasource: Name jdbc is not bound in this Context
at net.sf.hibernate.examples.quickstart.TestHibernateServlet.doGet(TestHibernateServlet.java:48)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)


<from Tomcat console>
19:54:46,822 INFO NamingHelper:26 - JNDI InitialContext properties:{}
19:54:46,916 FATAL DatasourceConnectionProvider:47 - Could not find datasource: java:comp/env/jdbc/quickstart
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:811)
at org.apache.naming.NamingContext.lookup(NamingContext.java:181)
at org.apache.naming.NamingContext.lookup(NamingContext.java:822)
at org.apache.naming.NamingContext.lookup(NamingContext.java:181)
at org.apache.naming.NamingContext.lookup(NamingContext.java:822)
at org.apache.naming.NamingContext.lookup(NamingContext.java:194)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:183)

I have add the <Context path="quickstart" docBase="/quickstart"> in my Tomcat server.xml according to the QuickStart Document.

And I check my database connection parameters to make sure they are correct (I use the same parameters in a DB tool and I am able to connect).

Can someone please help me how to resolve this issue?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 11:01 pm 
Newbie

Joined: Tue Oct 21, 2003 11:41 am
Posts: 11
I am able to get further, now I can't create a connection to the database.

again, I have added the following in my server.xml of Tomcat:
<Context path="quickstart" docBase="/quickstart">
<Resource name="jdbc/quickstart" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/quickstart">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>

<!-- DBCP database connection settings -->
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/mysql</value>
</parameter>
<parameter>
<name>driverClassName</name><value>org.gjt.mm.mysql.Driver</value>
</parameter>
<parameter>
<name>username</name>
<value>remote</value>
</parameter>
<parameter>
<name>password</name>
<value>remote</value>
</parameter>

<!-- DBCP connection pooling options -->
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>

</ResourceParams>
</Context>

<< from the Tomcat console >>
20:56:49,010 INFO DatasourceConnectionProvider:51 - Using datasource: java:comp/env/jdbc/quickstart
20:56:49,010 INFO SessionFactoryImpl:155 - Use outer join fetching: true
20:56:49,057 WARN JDBCExceptionReporter:36 - SQL Error: 0, SQLState: null
20:56:49,057 ERROR JDBCExceptionReporter:44 - Cannot load JDBC driver class 'null'
20:56:49,072 WARN SessionFactoryImpl:171 - Could not obtain connection metadata
java.sql.SQLException: Cannot load JDBC driver class 'null'
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:529)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:312)
at net.sf.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:60)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:160)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:594)
at net.sf.hibernate.examples.quickstart.TestHibernateServlet.initHibernate(TestHibernateServlet.java:109)
at net.sf.hibernate.examples.quickstart.TestHibernateServlet.doGet(TestHibernateServlet.java:26)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 3:47 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Thats a fascinating new Tomcat/DBCP exception I've seen in the last couple days too! I've never seen it the years before and I'm sure the Quickstart works. I'll check that soon and post an update. I suggest you start with a fresh Tomcat (untar from distribution!) and make sure you don't have any JARs copied to the common/lib, only the single jdbc-driver.jar!

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 10:20 am 
Newbie

Joined: Tue Oct 21, 2003 11:41 am
Posts: 11
I copy the Jakarta Commons DBCP and Pool (version 1.0) Jar to common/lib of my Tomcat install directory.

But it does not work even when I remove those jars.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 10:23 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Please read my suggestion again. Start with a fresh Tomcat and don't mess around with your broken setup.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 9:35 pm 
Newbie

Joined: Tue Oct 21, 2003 11:41 am
Posts: 11
Thanks for your suggestion. I try that , but I am stuck with the same issue.

I am using Tomcat 4.1.27 with mySQL JDBC driver verision 3.0.7.

I appreciate if you have any more ideas.

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 3:24 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I'm using Tomcat 4.1.24, try that one.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 9:11 pm 
Newbie

Joined: Tue Oct 21, 2003 11:41 am
Posts: 11
Thanks for your suggestion again. I switch a fresh 4.1.24 tomcat, but it still does not work.

I got this exception:
19:04:09,750 FATAL DatasourceConnectionProvider:47 - Could not find datasource: java:comp/env/jdbc/quickstart
javax.naming.NamingException: Cannot create resource instance
at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:189)
at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)

Here is what I add in my tomcat server.xml:
<Context path="quickstart" docBase="/quickstart">

<Resource name="jdbc/quickstart" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/quickstart">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>

<!-- DBCP database connection settings -->
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/mysql</value>
</parameter>
<parameter>
<name>driverClassName</name><value>org.gjt.mm.mysql.Driver</value>
</parameter>
<parameter>
<name>username</name>
<value>remote</value>
</parameter>
<parameter>
<name>password</name>
<value>remote</value>
</parameter>

<!-- DBCP connection pooling options -->
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>

</ResourceParams>
</Context>

I appreciate if you have more suggestion.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 10:27 pm 
Newbie

Joined: Tue Oct 21, 2003 11:41 am
Posts: 11
I find this IllegalArgumentException in my tomcat log:
java.lang.IllegalArgumentException: Document base C:\JavaSandbox\jakarta-tomcat-4.1.24-LE-jdk14\webapps\quickstart does not exist or is not a readable directory

Do I need to create a directory \webapps\quickstart manually?


2003-10-24 20:19:50 StandardContext[quickstart]: Starting
2003-10-24 20:19:50 StandardContext[quickstart]: Processing start(), current available=false
2003-10-24 20:19:50 StandardContext[quickstart]: Configuring default Resources
2003-10-24 20:19:50 StandardContext[quickstart]: Resources start failed:
java.lang.IllegalArgumentException: Document base C:\JavaSandbox\jakarta-tomcat-4.1.24-LE-jdk14\webapps\quickstart does not exist or is not a readable directory
at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:193)
at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:3342)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3472)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:738)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:347)
at org.apache.catalina.core.StandardService.start(StandardService.java:497)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:2190)
at org.apache.catalina.startup.Catalina.start(Catalina.java:512)
at org.apache.catalina.startup.Catalina.execute(Catalina.java:400)
at org.apache.catalina.startup.Catalina.process(Catalina.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:203)

2003-10-24 20:19:50 StandardContext[quickstart]: Configuring non-privileged default Loader
2003-10-24 20:19:50 StandardContext[quickstart]: Configuring default Manager
2003-10-24 20:19:50 StandardContext[quickstart]: Processing standard container startup
2003-10-24 20:19:50 StandardContext[quickstart]: Context startup failed due to previous errors
2003-10-24 20:19:50 StandardContext[quickstart]: Exception during cleanup after start failed
LifecycleException: Container StandardContext[quickstart] has not been started
at org.apache.catalina.core.StandardContext.stop(StandardContext.java:3643)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3621)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:738)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:347)
at org.apache.catalina.core.StandardService.start(StandardService.java:497)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:2190)
at org.apache.catalina.startup.Catalina.start(Catalina.java:512)
at org.apache.catalina.startup.Catalina.execute(Catalina.java:400)
at org.apache.catalina.startup.Catalina.process(Catalina.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:203)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 25, 2003 2:19 am 
Regular
Regular

Joined: Tue Sep 02, 2003 5:09 pm
Posts: 81
Location: Whitefish Montana
It would seem that you should either have docBase="quickstart" or docBase="C:\JavaSandbox\jakarta-tomcat-4.1.24-LE-jdk14\webapps\quickstart" or no docBase. I have not used the JNDI support for MySql in a while but I looked at an old configuration and I used <name>DriverName</name> rather than <name>url</name>. I also use the newer driver rather than the gjt driver, but that is obviously not causing your problem.


[quote="yinglcs"]

Here is what I add in my tomcat server.xml:
<Context path="quickstart" docBase="/quickstart">


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 25, 2003 2:33 am 
Newbie

Joined: Tue Oct 21, 2003 11:41 am
Posts: 11
I think I resolve my problem. Thanks for all the help.

Thanks.


Top
 Profile  
 
 Post subject: Same problem, how did you fix it?
PostPosted: Tue Nov 04, 2003 3:10 pm 
Newbie

Joined: Tue Nov 04, 2003 3:04 pm
Posts: 4
I am getting the same error and have tried all the above suggestions. How did you finally fix the issue and what was causing the problem?


Could not find datasource: 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
Nov 4, 2003 1:01:35 PM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Nov 4, 2003 1:01:35 PM net.sf.hibernate.dialect.Dialect <init>
INFO: Using dialect: net.sf.hibernate.dialect.MySQLDialect
Nov 4, 2003 1:01:35 PM net.sf.hibernate.util.NamingHelper getInitialContext
INFO: JNDI InitialContext properties:{}
Nov 4, 2003 1:01:35 PM net.sf.hibernate.connection.DatasourceConnectionProvider configure
SEVERE: Could not find datasource: java:comp/env/jdbc/quickstart
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:640)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:45)
at net.sf.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:83)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:153)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:627)
at testHibernate.<init>(testHibernate.java:19)
at testHibernate.main(testHibernate.java:43)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 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.