You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Lucas Bee <lb...@email.arizona.edu> on 2006/03/01 18:12:12 UTC

Tomcat - Hibernate

Hello Fellow Users,

 

My question is relatively simple.  It has 3 parts.

 

1.	Database:

*         MySQL 4.1

 

2.	Tomcat:

*         Apache Tomcat/5.0.28

 

3.	Hibernate:

*         2.1.8

 

I have my app which uses Hibernate and connects to a MySQL database and uses
Tomcat as the app server.  Everything works just fine except for when I need
to redeploy an app.  I go into Tomcat Manager and stop the app and then
undeploy the app.  Everything works here as well, however, when I try to
redeploy the app it redeploys but my app can't connect to the database until
after I restart Tomcat.  This is a problem when you are redeploying to the
production server.   This might be more of a hibernate setting question but
I thought it could be beneficial to post here as well since the Hibernate
Forum is not providing any results.

 

Code:

 

Tomcat Server.xml

 

<Context path="/Cohorts" docBase="Cohorts" reloadable="true"
crossContext="true">

 

    <Resource name="jdbc/dbus5" scope="Shareable"
type="javax.sql.DataSource"/>

 

    <ResourceParams name="jdbc/dbus5">

 

        <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/us?autoReconnect=true</value>

        </parameter>

        <parameter>

            <name>driverClassName</name><value>com.mysql.jdbc.Driver</value>

        </parameter>

       

           .....

 

        <!-- DBCP connection pooling options -->

           .....

    </ResourceParams>

</Context> 

 

Hibernate.cfg.xml

 

<property name="connection.datasource">java:comp/env/jdbc/dbus5</property>

      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

 

That's it!  Is there some setting I'm missing in my server.xml file?  I
really don't know.  I've searched every place I can think of.

 

Any feedback would be great!

 

Thanks.

 

-Lucas

 


RE: Tomcat - Hibernate

Posted by Lucas Bee <lb...@email.arizona.edu>.
Thanks to both who responded to my question.  I will work on creating the
xml fragment and get back with you on the results.  The information you
provided was very helpful and is pointing me in the right direction.

-Lucas 

-----Original Message-----
From: Nikola Milutinovic [mailto:alokin1@yahoo.com] 
Sent: Thursday, March 02, 2006 1:28 AM
To: Tomcat Users List
Subject: Re: Tomcat - Hibernate



--- Giorgio Clavelli <gi...@gmail.com> wrote:

> Hi,
> I'm not an exper at all, but I try to put my 2 cents.
> The fact that your app can connect successfully after the server restart,
> suggests that you should have your app's context.xml (or whatever it is
> called) not in the server.xml but in the correct location inside your app
> directories. I seem to have read, the correct location being under the
> META-INF directory and that Tomcat tries first to look for context in this
> dir and then  use that one under server.xml.
> I hope expert user, will comfirm in one way or the other this
understanding
> of your problem.

As of TC 5.0 the prefered way of configuring a context (web application) is
to
use a XML context fragment file. That file will either be placed in
${CATALINA_HOME}/conf/${HOSTNAME}/${CONTEXT_NAME}.xml, if you're deploying
from
a directory or in ./META-INF/${CONTEXT_NAME}.xml, if it is a WAR file.

That way, deploying of an app can be free from editing the server.xml.

As for the original problem, that is NOT it. The fact that TC's restart
picks
up everything suggests that the config is OK. Or at least relatively OK. I
think that TC will create a XML fragment for the app and it could be that
*that* fragment is interfering with the deployment process.

Since I can see nothing wrong with the config, I would advise the original
poster to go the correct route. Create the config fragment, pack it into
your
WAR, clean up server.xml and try to deploy/undeploy/redeploy. It will have
no
effect on TC 4.x, if you're warried that you might be forced to use it some
day, TC4 ignores that file (one question to the authoritative guys: will
that
dir be accessable? - a potential security hole).

Nix.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Tomcat - Hibernate

Posted by Tim Lucia <ti...@yahoo.com>.
If deploying a war, then the correct place to put the context, regardless of
the war name is in the war, under META-INF/context.xml.  Tomcat should then
create the deployment descriptor named according to the war (except .xml)
for you.  You would not supply the context file separately in this case.

Tim

-----Original Message-----
From: Lucas Bee [mailto:lbee@email.arizona.edu] 
Sent: Thursday, March 02, 2006 5:11 PM
To: 'Tomcat Users List'
Subject: RE: Tomcat - Hibernate

Hello,

I think we are getting very close I just need clarification on a few things.
First off I made the changes of taking out the Context setting in the
server.xml and created a context.xml file and put it into the META-INF
directory of my application. (Side note: I think this is a lot easier and
cleaner way of doing it) 

I deployed my war file through Tomcat Manager with the context.xml file in
the META-INF directory and it would deploy but not connect to the database.
So, I also put the context.xml file in the following path:

${CATALINA_HOME}/conf/${ENGINE_NAME}/${HOSTNAME}/${CONTEXT_NAME}.xml

This would work great, but I still had to restart TC once I did this.

<!------------------- Question 1 -------------------------------------->

First Question:  Is this correct to place the context.xml file in both
places when uploading with a WAR through Tomcat Manager?

I reviewed both these resources for more information but I didn't really
find what I was looking for.

http://tomcat.apache.org/tomcat-5.5-doc/deployer-howto.html

http://tomcat.apache.org/tomcat-5.5-doc/manager-howto.html


<!------------------- End Question 1 -------------------------------------->

What I would like to do is use Tomcat Manager to deploy, undeploy and
redeploy my apps. But remotely there is no way to upload the context.xml
file into the correct
${CATALINA_HOME}/conf/${ENGINE_NAME}/${HOSTNAME}/${CONTEXT_NAME}.xml path.

Below is an example of my context.xml file that I put into my META-INF.  I
don't think you would have to change anything from the server.xml to this,
but I'm not sure.

<!---------------------- CODE -------------------------------------------->

<!-- Context path for application Cohorts -->
<Context path="/Cohorts" docBase="Cohorts"  reloadable="true"
crossContext="true">

    <Resource name="jdbc/dbus5" scope="Shareable"
type="javax.sql.DataSource"/>

    <ResourceParams name="jdbc/dbus5">

        <parameter>
            <name>factory</name>
            <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
        </parameter>

        <!-- DBCP database connection settings -->
        <parameter>
            <name>url</name>
            <value>jdbc:mysql://server:3306/us?autoReconnect=true</value>
        </parameter>
        <parameter>
            <name>driverClassName</name><value>com.mysql.jdbc.Driver</value>
        </parameter>
       ...
    </ResourceParams>
</Context>

<!------------ End Code --------------------------------------------------->


<!------------------------------- Server.xml Settings --------------------->

<Host name="localhost" debug="0" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">

<!---------------------------- End Server.xml Settings ------------------->

Thanks again for all your help.

-Lucas

-----Original Message-----
From: Tim Lucia [mailto:timlucia@yahoo.com] 
Sent: Thursday, March 02, 2006 5:22 AM
To: 'Tomcat Users List'
Subject: RE: Tomcat - Hibernate

You want ENGINE_NAME in there too, i.e.:

${CATALINA_HOME}/conf/${ENGINE_NAME}/${HOSTNAME}/${CONTEXT_NAME}.xml

or, for example (spaces delineate variables above, don't really use them),

/usr/local/tomcat /conf /Catalina /localhost /ROOT.xml ==>
http://localhost:8080/

/usr/local/tomcat /conf /Catalina /localhost /myapp.xml ==>
http://localhost:8080/myapp

Tim

-----Original Message-----
From: Nikola Milutinovic [mailto:alokin1@yahoo.com] 
Sent: Thursday, March 02, 2006 3:28 AM
To: Tomcat Users List
Subject: Re: Tomcat - Hibernate



--- Giorgio Clavelli <gi...@gmail.com> wrote:

> Hi,
> I'm not an exper at all, but I try to put my 2 cents.
> The fact that your app can connect successfully after the server restart,
> suggests that you should have your app's context.xml (or whatever it is
> called) not in the server.xml but in the correct location inside your app
> directories. I seem to have read, the correct location being under the
> META-INF directory and that Tomcat tries first to look for context in this
> dir and then  use that one under server.xml.
> I hope expert user, will comfirm in one way or the other this
understanding
> of your problem.

As of TC 5.0 the prefered way of configuring a context (web application) is
to
use a XML context fragment file. That file will either be placed in
${CATALINA_HOME}/conf/${HOSTNAME}/${CONTEXT_NAME}.xml, if you're deploying
from
a directory or in ./META-INF/${CONTEXT_NAME}.xml, if it is a WAR file.

That way, deploying of an app can be free from editing the server.xml.

As for the original problem, that is NOT it. The fact that TC's restart
picks
up everything suggests that the config is OK. Or at least relatively OK. I
think that TC will create a XML fragment for the app and it could be that
*that* fragment is interfering with the deployment process.

Since I can see nothing wrong with the config, I would advise the original
poster to go the correct route. Create the config fragment, pack it into
your
WAR, clean up server.xml and try to deploy/undeploy/redeploy. It will have
no
effect on TC 4.x, if you're warried that you might be forced to use it some
day, TC4 ignores that file (one question to the authoritative guys: will
that
dir be accessable? - a potential security hole).

Nix.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Tomcat - Hibernate

Posted by Lucas Bee <lb...@email.arizona.edu>.
Hello,

I think we are getting very close I just need clarification on a few things.
First off I made the changes of taking out the Context setting in the
server.xml and created a context.xml file and put it into the META-INF
directory of my application. (Side note: I think this is a lot easier and
cleaner way of doing it) 

I deployed my war file through Tomcat Manager with the context.xml file in
the META-INF directory and it would deploy but not connect to the database.
So, I also put the context.xml file in the following path:

${CATALINA_HOME}/conf/${ENGINE_NAME}/${HOSTNAME}/${CONTEXT_NAME}.xml

This would work great, but I still had to restart TC once I did this.

<!------------------- Question 1 -------------------------------------->

First Question:  Is this correct to place the context.xml file in both
places when uploading with a WAR through Tomcat Manager?

I reviewed both these resources for more information but I didn't really
find what I was looking for.

http://tomcat.apache.org/tomcat-5.5-doc/deployer-howto.html

http://tomcat.apache.org/tomcat-5.5-doc/manager-howto.html


<!------------------- End Question 1 -------------------------------------->

What I would like to do is use Tomcat Manager to deploy, undeploy and
redeploy my apps. But remotely there is no way to upload the context.xml
file into the correct
${CATALINA_HOME}/conf/${ENGINE_NAME}/${HOSTNAME}/${CONTEXT_NAME}.xml path.

Below is an example of my context.xml file that I put into my META-INF.  I
don't think you would have to change anything from the server.xml to this,
but I'm not sure.

<!---------------------- CODE -------------------------------------------->

<!-- Context path for application Cohorts -->
<Context path="/Cohorts" docBase="Cohorts"  reloadable="true"
crossContext="true">

    <Resource name="jdbc/dbus5" scope="Shareable"
type="javax.sql.DataSource"/>

    <ResourceParams name="jdbc/dbus5">

        <parameter>
            <name>factory</name>
            <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
        </parameter>

        <!-- DBCP database connection settings -->
        <parameter>
            <name>url</name>
            <value>jdbc:mysql://server:3306/us?autoReconnect=true</value>
        </parameter>
        <parameter>
            <name>driverClassName</name><value>com.mysql.jdbc.Driver</value>
        </parameter>
       ...
    </ResourceParams>
</Context>

<!------------ End Code --------------------------------------------------->


<!------------------------------- Server.xml Settings --------------------->

<Host name="localhost" debug="0" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">

<!---------------------------- End Server.xml Settings ------------------->

Thanks again for all your help.

-Lucas

-----Original Message-----
From: Tim Lucia [mailto:timlucia@yahoo.com] 
Sent: Thursday, March 02, 2006 5:22 AM
To: 'Tomcat Users List'
Subject: RE: Tomcat - Hibernate

You want ENGINE_NAME in there too, i.e.:

${CATALINA_HOME}/conf/${ENGINE_NAME}/${HOSTNAME}/${CONTEXT_NAME}.xml

or, for example (spaces delineate variables above, don't really use them),

/usr/local/tomcat /conf /Catalina /localhost /ROOT.xml ==>
http://localhost:8080/

/usr/local/tomcat /conf /Catalina /localhost /myapp.xml ==>
http://localhost:8080/myapp

Tim

-----Original Message-----
From: Nikola Milutinovic [mailto:alokin1@yahoo.com] 
Sent: Thursday, March 02, 2006 3:28 AM
To: Tomcat Users List
Subject: Re: Tomcat - Hibernate



--- Giorgio Clavelli <gi...@gmail.com> wrote:

> Hi,
> I'm not an exper at all, but I try to put my 2 cents.
> The fact that your app can connect successfully after the server restart,
> suggests that you should have your app's context.xml (or whatever it is
> called) not in the server.xml but in the correct location inside your app
> directories. I seem to have read, the correct location being under the
> META-INF directory and that Tomcat tries first to look for context in this
> dir and then  use that one under server.xml.
> I hope expert user, will comfirm in one way or the other this
understanding
> of your problem.

As of TC 5.0 the prefered way of configuring a context (web application) is
to
use a XML context fragment file. That file will either be placed in
${CATALINA_HOME}/conf/${HOSTNAME}/${CONTEXT_NAME}.xml, if you're deploying
from
a directory or in ./META-INF/${CONTEXT_NAME}.xml, if it is a WAR file.

That way, deploying of an app can be free from editing the server.xml.

As for the original problem, that is NOT it. The fact that TC's restart
picks
up everything suggests that the config is OK. Or at least relatively OK. I
think that TC will create a XML fragment for the app and it could be that
*that* fragment is interfering with the deployment process.

Since I can see nothing wrong with the config, I would advise the original
poster to go the correct route. Create the config fragment, pack it into
your
WAR, clean up server.xml and try to deploy/undeploy/redeploy. It will have
no
effect on TC 4.x, if you're warried that you might be forced to use it some
day, TC4 ignores that file (one question to the authoritative guys: will
that
dir be accessable? - a potential security hole).

Nix.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Tomcat - Hibernate

Posted by Tim Lucia <ti...@yahoo.com>.
You want ENGINE_NAME in there too, i.e.:

${CATALINA_HOME}/conf/${ENGINE_NAME}/${HOSTNAME}/${CONTEXT_NAME}.xml

or, for example (spaces delineate variables above, don't really use them),

/usr/local/tomcat /conf /Catalina /localhost /ROOT.xml ==>
http://localhost:8080/

/usr/local/tomcat /conf /Catalina /localhost /myapp.xml ==>
http://localhost:8080/myapp

Tim

-----Original Message-----
From: Nikola Milutinovic [mailto:alokin1@yahoo.com] 
Sent: Thursday, March 02, 2006 3:28 AM
To: Tomcat Users List
Subject: Re: Tomcat - Hibernate



--- Giorgio Clavelli <gi...@gmail.com> wrote:

> Hi,
> I'm not an exper at all, but I try to put my 2 cents.
> The fact that your app can connect successfully after the server restart,
> suggests that you should have your app's context.xml (or whatever it is
> called) not in the server.xml but in the correct location inside your app
> directories. I seem to have read, the correct location being under the
> META-INF directory and that Tomcat tries first to look for context in this
> dir and then  use that one under server.xml.
> I hope expert user, will comfirm in one way or the other this
understanding
> of your problem.

As of TC 5.0 the prefered way of configuring a context (web application) is
to
use a XML context fragment file. That file will either be placed in
${CATALINA_HOME}/conf/${HOSTNAME}/${CONTEXT_NAME}.xml, if you're deploying
from
a directory or in ./META-INF/${CONTEXT_NAME}.xml, if it is a WAR file.

That way, deploying of an app can be free from editing the server.xml.

As for the original problem, that is NOT it. The fact that TC's restart
picks
up everything suggests that the config is OK. Or at least relatively OK. I
think that TC will create a XML fragment for the app and it could be that
*that* fragment is interfering with the deployment process.

Since I can see nothing wrong with the config, I would advise the original
poster to go the correct route. Create the config fragment, pack it into
your
WAR, clean up server.xml and try to deploy/undeploy/redeploy. It will have
no
effect on TC 4.x, if you're warried that you might be forced to use it some
day, TC4 ignores that file (one question to the authoritative guys: will
that
dir be accessable? - a potential security hole).

Nix.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat - Hibernate

Posted by Nikola Milutinovic <al...@yahoo.com>.

--- Giorgio Clavelli <gi...@gmail.com> wrote:

> Hi,
> I'm not an exper at all, but I try to put my 2 cents.
> The fact that your app can connect successfully after the server restart,
> suggests that you should have your app's context.xml (or whatever it is
> called) not in the server.xml but in the correct location inside your app
> directories. I seem to have read, the correct location being under the
> META-INF directory and that Tomcat tries first to look for context in this
> dir and then  use that one under server.xml.
> I hope expert user, will comfirm in one way or the other this understanding
> of your problem.

As of TC 5.0 the prefered way of configuring a context (web application) is to
use a XML context fragment file. That file will either be placed in
${CATALINA_HOME}/conf/${HOSTNAME}/${CONTEXT_NAME}.xml, if you're deploying from
a directory or in ./META-INF/${CONTEXT_NAME}.xml, if it is a WAR file.

That way, deploying of an app can be free from editing the server.xml.

As for the original problem, that is NOT it. The fact that TC's restart picks
up everything suggests that the config is OK. Or at least relatively OK. I
think that TC will create a XML fragment for the app and it could be that
*that* fragment is interfering with the deployment process.

Since I can see nothing wrong with the config, I would advise the original
poster to go the correct route. Create the config fragment, pack it into your
WAR, clean up server.xml and try to deploy/undeploy/redeploy. It will have no
effect on TC 4.x, if you're warried that you might be forced to use it some
day, TC4 ignores that file (one question to the authoritative guys: will that
dir be accessable? - a potential security hole).

Nix.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat - Hibernate

Posted by Giorgio Clavelli <gi...@gmail.com>.
Hi,
I'm not an exper at all, but I try to put my 2 cents.
The fact that your app can connect successfully after the server restart,
suggests that you should have your app's context.xml (or whatever it is
called) not in the server.xml but in the correct location inside your app
directories. I seem to have read, the correct location being under the
META-INF directory and that Tomcat tries first to look for context in this
dir and then  use that one under server.xml.
I hope expert user, will comfirm in one way or the other this understanding
of your problem.

On 3/2/06, Lucas Bee <lb...@email.arizona.edu> wrote:
>
> Hello Fellow Users,
>
>
>
> My question is relatively simple.  It has 3 parts.
>
>
>
> 1.      Database:
>
> *         MySQL 4.1
>
>
>
> 2.      Tomcat:
>
> *         Apache Tomcat/5.0.28
>
>
>
> 3.      Hibernate:
>
> *         2.1.8
>
>
>
> I have my app which uses Hibernate and connects to a MySQL database and
> uses
> Tomcat as the app server.  Everything works just fine except for when I
> need
> to redeploy an app.  I go into Tomcat Manager and stop the app and then
> undeploy the app.  Everything works here as well, however, when I try to
> redeploy the app it redeploys but my app can't connect to the database
> until
> after I restart Tomcat.  This is a problem when you are redeploying to the
> production server.   This might be more of a hibernate setting question
> but
> I thought it could be beneficial to post here as well since the Hibernate
> Forum is not providing any results.
>
>
>
> Code:
>
>
>
> Tomcat Server.xml
>
>
>
> <Context path="/Cohorts" docBase="Cohorts" reloadable="true"
> crossContext="true">
>
>
>
>     <Resource name="jdbc/dbus5" scope="Shareable"
> type="javax.sql.DataSource"/>
>
>
>
>     <ResourceParams name="jdbc/dbus5">
>
>
>
>         <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/us?autoReconnect=true</value>
>
>         </parameter>
>
>         <parameter>
>
>             <name>driverClassName</name><value>com.mysql.jdbc.Driver
> </value>
>
>         </parameter>
>
>
>
>            .....
>
>
>
>         <!-- DBCP connection pooling options -->
>
>            .....
>
>     </ResourceParams>
>
> </Context>
>
>
>
> Hibernate.cfg.xml
>
>
>
> <property name="connection.datasource">java:comp/env/jdbc/dbus5</property>
>
>       <property name="dialect">org.hibernate.dialect.MySQLDialect
> </property>
>
>
>
> That's it!  Is there some setting I'm missing in my server.xml file?  I
> really don't know.  I've searched every place I can think of.
>
>
>
> Any feedback would be great!
>
>
>
> Thanks.
>
>
>
> -Lucas
>
>
>
>
>