You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Brian McGovern <bm...@imediainc.com> on 2005/03/29 20:40:56 UTC

Struts , hibernate, and DBCP

Im using struts, hibernate and dbcp connection pooling.  Everything works fine but regarding my connection pool.  It gets intantiated on the first time I request a connection from the DBCP pool.  I want it to create the pool when tomcat starts.  I think i can do this with struts, but im not sure how.  If using struts config for htis is not the answer i;d still like to know what is. 

-thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts , hibernate, and DBCP

Posted by N G <ni...@gmail.com>.
Oh... I didn't know that DBCP doesn't initialize the pool on server
startup and thus misunderstood your question.

Truth is, if you want to go the easiest route, without having to make
your own Controller, you can just configure your Hibernate
SessionFactory in a listener
(ServletContextListener.contextInitialized()). It will FOR SURE fire
up on start up of your application before struts action servlet is
even loaded.

HTH,
NG.


On Tue, 29 Mar 2005 14:58:12 -0500, Erik Weber <er...@mindspring.com> wrote:
> In my opinion, the question is on topic.
> 
> I'm not sure whether by "instantiated" you mean the pool class or the
> connection class. If it's the former, I'm not sure of the answer, but I
> would assume that the pool class typically is instantiated at server
> startup. If not, wouldn't the JNDI lookup fail? If it's the latter, I
> think specifying the minimum connection count property (> 0) in your
> datasource config should cause the pool to be primed right after
> startup. But, it's up to the pool implementation of course. But the
> minimum connection count is supposed to keep the pool from going dry.
> 
> Erik
> 
> 
> N G wrote:
> 
> >This has nothing to do with Struts:
> >http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples-howto.html
> >
> >Good luck,
> >NG.
> >
> >
> >On Tue, 29 Mar 2005 13:40:56 -0500, Brian McGovern
> ><bm...@imediainc.com> wrote:
> >
> >
> >>Im using struts, hibernate and dbcp connection pooling.  Everything works fine but regarding my connection pool.  It gets intantiated on the first time I request a connection from the DBCP pool.  I want it to create the pool when tomcat starts.  I think i can do this with struts, but im not sure how.  If using struts config for htis is not the answer i;d still like to know what is.
> >>
> >>-thanks
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >>
> >>
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts , hibernate, and DBCP

Posted by Erik Weber <er...@mindspring.com>.
In my opinion, the question is on topic.

I'm not sure whether by "instantiated" you mean the pool class or the 
connection class. If it's the former, I'm not sure of the answer, but I 
would assume that the pool class typically is instantiated at server 
startup. If not, wouldn't the JNDI lookup fail? If it's the latter, I 
think specifying the minimum connection count property (> 0) in your 
datasource config should cause the pool to be primed right after 
startup. But, it's up to the pool implementation of course. But the 
minimum connection count is supposed to keep the pool from going dry.

Erik


N G wrote:

>This has nothing to do with Struts:
>http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples-howto.html
>
>Good luck,
>NG.
>
>
>On Tue, 29 Mar 2005 13:40:56 -0500, Brian McGovern
><bm...@imediainc.com> wrote:
>  
>
>>Im using struts, hibernate and dbcp connection pooling.  Everything works fine but regarding my connection pool.  It gets intantiated on the first time I request a connection from the DBCP pool.  I want it to create the pool when tomcat starts.  I think i can do this with struts, but im not sure how.  If using struts config for htis is not the answer i;d still like to know what is.
>>
>>-thanks
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts , hibernate, and DBCP

Posted by N G <ni...@gmail.com>.
This has nothing to do with Struts:
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples-howto.html

Good luck,
NG.


On Tue, 29 Mar 2005 13:40:56 -0500, Brian McGovern
<bm...@imediainc.com> wrote:
> Im using struts, hibernate and dbcp connection pooling.  Everything works fine but regarding my connection pool.  It gets intantiated on the first time I request a connection from the DBCP pool.  I want it to create the pool when tomcat starts.  I think i can do this with struts, but im not sure how.  If using struts config for htis is not the answer i;d still like to know what is.
> 
> -thanks
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts , hibernate, and DBCP

Posted by "David G. Friedman" <hu...@ix.netcom.com>.
Brian,

If you use a Tomcat resource reference to initialize your DB pool, be
careful where you put it: the location you place that init reference makes
the difference between YOUR webapp using the hibernate pool and ANY webapp
being able to use your hibernate pool.

Now, since someone posted about a Servlet Context Listener starting up
Hibernate for you, what is wrong with the one given on the hibernate site
under the page title "Tomcat Event listener for Hibernate" at the URL
http://www.hibernate.org/133.html ?

The example code shows how to have the hibernate configuration read.  You
can easily put pool information in your hibernate.cfg.xml file so Hibernate
starts the DB Pool for you.  (I do that)  Additionally, it lists how, should
you need it, to have a DB Pool instance automatically given out when a
session object is created and how to remove it when a session is ended.

Lastly, if you use C3P0, BE VERY CAREFUL if you are using version 0.8.3 of
C3P0 - there is no proper DB Pool shutdown code in Hibernate if the pool is
of that type (I last checked Hibernate 2.1.6's pool shutdown code).
Proxool, EHCache, and various other pool software have code in the db class
shutdown method in as far as I know.  (I had to research this when I had a
memory issue and kept restarting my webapp yet memory usage kept rising and
I kept seeing new DB pools each webapp restart.)

Regards,
David

-----Original Message-----
From: Brian McGovern [mailto:bmcgovern@imediainc.com]
Sent: Tuesday, March 29, 2005 1:41 PM
To: Struts Users Mailing List
Subject: Struts , hibernate, and DBCP


Im using struts, hibernate and dbcp connection pooling.  Everything works
fine but regarding my connection pool.  It gets intantiated on the first
time I request a connection from the DBCP pool.  I want it to create the
pool when tomcat starts.  I think i can do this with struts, but im not sure
how.  If using struts config for htis is not the answer i;d still like to
know what is.

-thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org