users@glassfish.java.net

Glassfish + container managed connection pool + MySQL +

From: <forums_at_java.net>
Date: Fri, 21 Oct 2011 16:59:42 -0500 (CDT)

 Howdy,

I'm working on an web app using glassfish configured to use a MySQL
connection pool. It's been going swimingly until yesterday when I decided it
was time to create a bit that does some setup for the app when the
ServletContext is created. I created a very simple class that implements the
ServletContextListener interface and overrode the contextInitialized method
to make some db calls that I use to prepare the app for use. Prior to this I
was doing a lazy initialization of everything where those calls weren't made
until the first time that they were needed (lazy initialization was working
great). So the new intialization method seems to work fine (by that I mean I
see no exceptions) but after initialization when the app makes it's a
database call it fails to read all of the columns out of a row.

 

The evidence of this is that I make the call without the new initialization
code and step through the db call and see all of the columns pulled out of
the result set fine. After that I put the initialization back in and make the
same call on the same data and it fails in precisely the same place to read
some data out of the result set. 

 

Interestingly, I had a bunch of logic and a few db calls in the new
initialization code. I removed all of the db calls and everything worked
after that (the db call following intialization worked fine). I tried putting
each db call back in one at a time and regardless of what db call I put in,
the app would start up and I would then make the same call to read the same
row out of the db and it would fail to get data out of the same column.

 

So I guess my question is this: Is it possible to make db calls using a
container managed connection pool in a class that implements
ServletContextListener in the contextInitialized method? If so, are there any
special steps you need to take in order to use the db and allow the app to
work correctly afterwards?

 

Regards,

 

Tim


--
[Message sent by forum member 'timman']
View Post: http://forums.java.net/node/855945