Search code examples
javahibernatejpaglassfish-3derby

Glassfish Derby Connection Pool, Connections not returned to the pool


I am using Glassfish 3.1, JEE6 JPA Annotations, Hibernate provider and Derby database in my (simple) application. I seem to be having a lot of difficulties with connection pooling. Basically, my application worked fine without security, but now that I've create a security realm, I'm finding that I run of of connections no matter what size I set the pool to. Obviously, there is something that I'm doing in my code that means the connection is not being returned to the pool after the servlet request finishes.

I've seen various posting and advice on StackOverflow and have tried them all...nothing seems to work.

What I would like to know is this...How do I get logging and trace information out of Glassfish? I need to find out why it is not returning the connection to the pool. This way I hope to be able to find the source of the problem.

Many thanks!


Solution

  • Its always the first guess, that connections are not returned to the pool due to lack of cleaning up.

    Make sure that:

    • close all connections you open
    • close all EntityManagers that you used

    in every Path.

    It is good practice, do

    use

    try
    {
      //open
      //work
    }
    catch
    {
      //exception handling
    }
    finally
    {
      //close
    }
    

    anywhere where you handle those situations.

    Side Note: Static Analyzers like findbugs/sonar are able to detect those situations.