-->
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.  [ 2 posts ] 
Author Message
 Post subject: Tomcat / JNDI / JDBC DataSource woes
PostPosted: Thu Feb 05, 2004 1:50 am 
Regular
Regular

Joined: Wed Dec 31, 2003 4:26 am
Posts: 108
Location: Berkeley, CA
No matter how I try it, trying to use a Tomcat (5.0) container-provided data source (vs. Hibernate provided one) doesn't work for me. Here's the current state:

1. Exception:

Feb 4, 2004 9:46:25 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 0, SQLState: null
Feb 4, 2004 9:46:25 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Cannot create JDBC driver of class '' for connect URL 'null'
Feb 4, 2004 9:46:25 PM net.sf.hibernate.JDBCException <init>
SEVERE: Cannot open connection
org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null', cause:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:743)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:518)
at net.sf.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:59)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:257)
at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3157)
at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3140)
at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:61)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:703)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:184)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:132)
at net.sf.hibernate.loader.Loader.doList(Loader.java:949)
at net.sf.hibernate.loader.Loader.list(Loader.java:940)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:833)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1475)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1454)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1446)
at com.publishworks.merchandise.DataSource.fetchAll(DataSource.java:26)
...

2. The server.xml file (I didn't bother with a context for the DataSource, I made it globally available to all contexts):

Code:
<?xml version='1.0' encoding='utf-8'?>
<Server>
  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
  <GlobalNamingResources>
    <Environment name="simpleValue" type="java.lang.Integer" value="30"/>
    <Resource auth="Container" description="User database that can be updated and saved" name="UserDatabase" type="org.apache.catalina.UserDatabase"/>
    <Resource name="jdbc/PublishWorks" auth="Container" type="javax.sql.DataSource"/>
    <ResourceParams name="UserDatabase">
      <parameter>
        <name>factory</name>
        <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
      </parameter>
      <parameter>
        <name>pathname</name>
        <value>conf/tomcat-users.xml</value>
      </parameter>
    </ResourceParams>
    <ResourceParams name="jdbc/PublishWorks">
      <parameter>
        <name>factory</name>
        <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
      </parameter>
      <parameter>
        <name>validationQuery</name>
        <value>select 1;</value>
      </parameter>
      <parameter>
        <name>maxWait</name>
        <value>-1</value>
      </parameter>
      <parameter>
        <name>maxActive</name>
        <value>20</value>
      </parameter>
      <parameter>
        <name>password</name>
        <value>pw_dbo</value>
      </parameter>
      <parameter>
        <name>url</name>
        <value>jdbc:postgresql://localhost/PublishWorks</value>
      </parameter>
      <parameter>
        <name>driverClassName</name>
        <value>org.postgresql.Driver</value>
      </parameter>
      <parameter>
        <name>maxIdle</name>
        <value>10</value>
      </parameter>
      <parameter>
        <name>username</name>
        <value>pw_dbo</value>
      </parameter>
    </ResourceParams>
  </GlobalNamingResources>
  <Service name="Catalina">
    <Connector acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" port="8080" redirectPort="8443">
    </Connector>
    <Connector port="8009" protocol="AJP/1.3" protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler" redirectPort="8443">
    </Connector>
    <Engine defaultHost="localhost" name="Catalina">
      <Host appBase="webapps" name="localhost">
        <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_log." suffix=".txt" timestamp="true"/>
      </Host>
      <Logger className="org.apache.catalina.logger.FileLogger" prefix="catalina_log." suffix=".txt" timestamp="true"/>
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
    </Engine>
  </Service>
</Server>


3. The relevant web.xml snippet:

Code:
<web-app>
    <display-name>WELCOME 2 PublishWorks</display-name>

   <resource-ref>
      <description>PostgreSQL DataSource for PublishWorks</description>
      <res-ref-name>jdbc/PublishWorks</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      <res-sharing-scope>Sharable</res-sharing-scope>
   </resource-ref>

   <!-- other stuff removed -->
</web-app>


4. The hibernate.cfg.xml file:

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

<hibernate-configuration>

    <session-factory name="prajna:/naming/hibernate/SessionFactory">

        <!-- properties -->
         <property name="connection.datasource">java:comp/env/jdbc/PublishWorks</property>

        <property name="hibernate.dialect">net.sf.hibernate.dialect.PostgreSQLDialect</property>
        <property name="hibernate.query.substitutions">yes 'Y', no 'N'</property>

      <property name="hibernate.use_outer_join">true</property>
        <property name="hibernate.show_sql">true</property>

        <!-- mapping files -->
        <mapping jar="InterSight.hbm.jar" />

    </session-factory>

</hibernate-configuration>


Any help would be greatly appreciated.


Top
 Profile  
 
 Post subject: Tomcat / JNDI / JDBC DataSource woes
PostPosted: Fri Mar 19, 2004 2:27 pm 
Newbie

Joined: Fri Mar 19, 2004 2:09 pm
Posts: 3
Location: Edwardsville, IL
Try adding a context to your server.xml file. Inside the context place a resourcelink pointing to the datasource you defined in the global resources area. See the tomcat documentation for more details.


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