Re: [question] Tomcat 5.5 & JNDI DataSources -> [solution]

From: Laszlo Spoor (lspoor_cayenn..otmail.com)
Date: Thu Feb 10 2005 - 14:15:07 EST

  • Next message: Laszlo Spoor: "RE: Pagination query"

    Hi Eric!

    Thanks for your response! Your reply helped me in finding the solution. I
    even found an easier way to use a datasource:

    - copy jdbc library to $tomcat_home/common/lib
    - create a xml file, e.g. backoffice.xml (the name of the application) that
    contains:

    <Context context="/backoffice" docBase="${catalina.home}/webapps/backoffice"
             privileged="true" antiResourceLocking="false"
    antiJARLocking="false">

        <!-- maxActive: Maximum number of dB connections in pool. Make sure you
             configure your mysqld max_connections large enough to handle
             all of your db connections. Set to 0 for no limit.
             -->

        <!-- maxIdle: Maximum number of idle dB connections to retain in pool.
             Set to -1 for no limit. See also the DBCP documentation on this
             and the minEvictableIdleTimeMillis configuration parameter.
             -->

        <!-- maxWait: Maximum time to wait for a dB connection to become
    available
             in ms, in this example 10 seconds. An Exception is thrown if
             this timeout is exceeded. Set to -1 to wait indefinitely.
             -->

        <!-- username and password: MySQL dB username and password for dB
    connections -->

        <!-- driverClassName: Class name for the old mm.mysql JDBC driver is
             org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
             Class name for the official MySQL Connector/J driver is
    com.mysql.jdbc.Driver.
             -->

        <!-- url: The JDBC connection url for connecting to your MySQL dB.
             The autoReconnect=true argument to the url makes sure that the
             mm.mysql JDBC Driver will automatically reconnect if mysqld closed
    the
             connection. mysqld by default closes idle connections after 8
    hours.
             -->

    <Resource name="jdbc/PvaDS"
              auth="Container"
              type="javax.sql.DataSource"
              maxActive="100"
              maxIdle="30"
              maxWait="10000"
              username="pva"
              password="welcome1"
              driverClassName="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost:3306/pva_dev?autoReconnect=true"/>

    </Context>

    The actions taken in the modeler are the same as usual: in my example add:
    jdbc/PvaDS as the JNDI name. (Perhaps this a nice addon to the Cayenne
    Documentation?)

    One very important tip: 'start your database' *blush*, which I forgot.... I
    won't tell you how long it took me to figure that out ;)

    Regards, Laszlo

    Thanks again, laszlo
    >From: Eric Schneider <eri..entralparksoftware.com>
    >Reply-To: cayenne-use..bjectstyle.org
    >To: cayenne-use..bjectstyle.org
    >Subject: Re: [question] Tomcat 5.5 & JNDI DataSources
    >Date: Thu, 10 Feb 2005 10:25:11 -0500
    >
    >laszlo,
    >
    >I have a similar config for one of my projects...here's how I have it set
    >up:
    >
    >server.xml (this stuff is all between my GlobalNamingResources tags):
    >
    > <Resource name="jdbc/sophora" type="javax.sql.DataSource"/>
    > <ResourceParams name="jdbc/sophora">
    > <parameter>
    > <name>maxWait</name>
    > <value>5000</value>
    > </parameter>
    > <parameter>
    > <name>maxActive</name>
    > <value>6</value>
    > </parameter>
    > <parameter>
    > <name>password</name>
    > <value>crap</value>
    > </parameter>
    > <parameter>
    > <name>url</name>
    > <value>jdbc:mysql://localhost/sophora</value>
    > </parameter>
    > <parameter>
    > <name>driverClassName</name>
    > <value>org.gjt.mm.mysql.Driver</value>
    > </parameter>
    > <parameter>
    > <name>maxIdle</name>
    > <value>2</value>
    > </parameter>
    > <parameter>
    > <name>username</name>
    > <value>crap</value>
    > </parameter>
    > </ResourceParams>
    >
    >The new versions of tomcat have separate config files in
    >$CATALINA_HOME/conf/Catalina/localhost. In this directory I have an xml
    >file named processing.xml (which is my app name). It contains the
    >following:
    >
    ><?xml version='1.0' encoding='utf-8'?>
    ><Context crossContext="true" displayName="Sophora Processing Application"
    >docBase="processing" path="/processing" reloadable="true"
    >workDir="work/Catalina/localhost/processing">
    > <Logger className="org.apache.catalina.logger.FileLogger"
    >prefix="localhost_processing." suffix=".txt" timestamp="true"/>
    > <ResourceLink global="jdbc/sophora" name="jdbc/sophora"
    >type="javax.sql.DataSource"/>
    ></Context>
    >
    >In the modeler, I select the MySql adaptor, the JNDIDataSourceFactory, and
    >I use "jdbc/sophora" as the JNDI location.
    >
    >I don't have any additional configuration in my web.xml. I just lazily
    >initialize a DataContext on my Tapestry Visit object.
    >
    >Hope that helps.
    >e.
    >
    >
    >On Feb 10, 2005, at 10:03 AM, Laszlo Spoor wrote:
    >
    >>Cayenne 1.1
    >>MySQL 4.12
    >>Tomcat 5.5.7
    >>
    >>Hello,
    >>
    >>I want to use a JNDI DataSource for connecting to my Database. These are
    >>the steps I followed:
    >>
    >>- Used the modeler to tell Cayenne that I want to use the DataSource
    >>jdbc/PvaDS (as explained in the documentation)
    >>- Added to web.xml
    >> <listener>
    >> <listener-
    >>class>org.objectstyle.cayenne.conf.BasicServletConfiguration</
    >>listener-class>
    >> </listener>
    >>
    >> <resource-ref>
    >> <res-ref-name>jdbc/PvaDS</res-ref-name>
    >> <res-type>javax.sql.DataSource</res-type>
    >> <res-auth>Container</res-auth>
    >></resource-ref>
    >>
    >>- Added to server.xml (In <GlobalNamingResources>-tag):
    >>
    >><Resource name="jdbc/PvaDS"
    >> auth="Container"
    >> type="javax.sql.DataSource"
    >> factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
    >> maxActive="100"
    >> maxIdle="30"
    >> maxWait="10000"
    >> username="pva"
    >> password="welcome1"
    >> driverClassName="com.mysql.jdbc.Driver"
    >> url="jdbc:mysql://localhost:3306/pva_dev?autoReconnect=true"/>
    >>
    >>- Added to context.xml (in <Context>-tag):
    >>
    >><ResourceLink global="jdbc/PvaDS" name="jdbc/PvaDS"
    >>type="javax.sql.DataSource"/>
    >>
    >>I am certain that all references to the JNDI Datasource point to:
    >>jdbc/PvaDS. I have tried to use the factory:
    >>'org.objectstyle.cayenne.conn.ContainerPoolFactory', but then Tomcat does
    >>not want to start.
    >>
    >>Now, when I start Tomcat, I get the following message:
    >>
    >>15:12:14 ERROR (ManagerBase) -Exception loading sessions from persistent
    >>storage
    >>org.objectstyle.cayenne.ConfigurationException: [v.1.1 December 6 2004]
    >>Error during Configuration initialization. [v.1.1 December 6 2004] Load
    >>failures. Main configuration class:
    >>org.objectstyle.cayenne.conf.DefaultConfiguration, details:
    >> domain.node.name=ProvestaDomainNode, domain.node.datasource=jdbc/PvaDS,
    >>reason: DataSource load failed - Name jdbc is not bound in this Context
    >> at
    >>org.objectstyle.cayenne.conf.Configuration.initializeSharedConfiguratio
    >>n(Configuration.java:304)
    >> at
    >>org.objectstyle.cayenne.conf.Configuration.initializeSharedConfiguratio
    >>n(Configuration.java:278)
    >> at
    >>org.objectstyle.cayenne.conf.Configuration.initializeSharedConfiguratio
    >>n(Configuration.java:261)
    >> at
    >>org.objectstyle.cayenne.conf.Configuration.getSharedConfiguration(Confi
    >>guration.java:224)
    >> at
    >>org.objectstyle.cayenne.access.DataContext.awakeFromDeserialization(Dat
    >>aContext.java:350)
    >> at
    >>org.objectstyle.cayenne.access.DataContext.getObjectStore(DataContext.j
    >>ava:423)
    >> at
    >>org.objectstyle.cayenne.access.DataContext.readObject(DataContext.java:
    >>1872)
    >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    >> at
    >>sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja
    >>va:39)
    >> at
    >>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso
    >>rImpl.java:25)
    >> at java.lang.reflect.Method.invoke(Method.java:585)
    >> at
    >>java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:919)
    >> at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1813)
    >> at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:
    >>1713)
    >> at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
    >> at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
    >> at
    >>org.apache.catalina.session.StandardSession.readObject(StandardSession.
    >>java:1362)
    >> at
    >>org.apache.catalina.session.StandardSession.readObjectData(StandardSess
    >>ion.java:894)
    >> at
    >>org.apache.catalina.session.StandardManager.doLoad(StandardManager.java
    >>:393)
    >> at
    >>org.apache.catalina.session.StandardManager.load(StandardManager.java:
    >>320)
    >> at
    >>org.apache.catalina.session.StandardManager.start(StandardManager.java:
    >>634)
    >> at org.apache.catalina.core.ContainerBase.setManager(ContainerBase.java:
    >>431)
    >> at
    >>org.apache.catalina.startup.ContextConfig.managerConfig(ContextConfig.j
    >>ava:354)
    >> at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:
    >>970)
    >> at
    >>org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.
    >>java:249)
    >> at
    >>org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleS
    >>upport.java:119)
    >> at org.apache.catalina.core.StandardContext.start(StandardContext.java:
    >>4020)
    >> at
    >>org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.j
    >>ava:759)
    >> at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:
    >>739)
    >> at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
    >> at
    >>org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java
    >>:590)
    >> at
    >>org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.jav
    >>a:535)
    >> at
    >>org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:470)
    >> at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1106)
    >> at
    >>org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:
    >>310)
    >> at
    >>org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleS
    >>upport.java:119)
    >> at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1019)
    >> at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
    >> at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1011)
    >> at
    >>org.apache.catalina.core.StandardEngine.start(StandardEngine.java:440)
    >> at org.apache.catalina.core.StandardService.start(StandardService.java:
    >>450)
    >> at
    >>org.apache.catalina.core.StandardServer.start(StandardServer.java:683)
    >> at org.apache.catalina.startup.Catalina.start(Catalina.java:537)
    >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    >> at
    >>sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja
    >>va:39)
    >> at
    >>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso
    >>rImpl.java:25)
    >> at java.lang.reflect.Method.invoke(Method.java:585)
    >> at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:271)
    >> at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:409)
    >>Caused by: org.objectstyle.cayenne.ConfigurationException: [v.1.1
    >>December 6 2004] Load failures. Main configuration class:
    >>org.objectstyle.cayenne.conf.DefaultConfiguration, details:
    >> domain.node.name=ProvestaDomainNode, domain.node.datasource=jdbc/PvaDS,
    >>reason: DataSource load failed - Name jdbc is not bound in this Context
    >> at
    >>org.objectstyle.cayenne.conf.RuntimeLoadDelegate.finishedLoading(Runtim
    >>eLoadDelegate.java:560)
    >> at
    >>org.objectstyle.cayenne.conf.ConfigLoader.loadDomains(ConfigLoader.java
    >>:115)
    >> at
    >>org.objectstyle.cayenne.conf.DefaultConfiguration.initialize(DefaultCon
    >>figuration.java:185)
    >> at
    >>org.objectstyle.cayenne.conf.Configuration.initializeSharedConfiguratio
    >>n(Configuration.java:296)
    >> ... 48 more
    >>
    >>
    >>Can someone tell me what I am doing wrong?
    >>
    >>Thanks in advance, Laszlo Spoor
    >>
    >>_________________________________________________________________
    >>Play online games with your friends with MSN Messenger
    >>http://messenger.msn.nl/
    >>
    >

    _________________________________________________________________
    FREE pop-up blocking with the new MSN Toolbar – get it now!
    http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/



    This archive was generated by hypermail 2.0.0 : Thu Feb 10 2005 - 14:16:05 EST