Deprecated: Function eregi() is deprecated in /home/webworx/public_html/cutenews/show_news.php on line 41
Deprecated: Function eregi() is deprecated in /home/webworx/public_html/cutenews/inc/shows.inc.php on line 54
Deprecated: Function eregi() is deprecated in /home/webworx/public_html/cutenews/inc/shows.inc.php on line 54
Hibernate -- Too many connections problem
Hello java fellows,
I was refactoring a web application where I was using JPA - Hibernate - MySql.
When I was testing the application I noticed the database connections were growing and growing.
I figured out that the entitymanager did not close the connections.
The problem was in this line of code :
EntityManagerFactory emf = Persistence.createEntityManagerFactory("databasename");
I was using this code in a function. It created a EntityManagerFactory at each execution of the function.
The solution was creating a singleton which needs to check if there already is an instance of the EntityManagerFactory. If there was an instance I needed to grab the instance instead of creating an new EntityManagerFactory.
The full explanation I found on this blog :
http://javanotepad.blogspot.com/2007/05/jpa-entitymanagerfactory-in-web.html
I was refactoring a web application where I was using JPA - Hibernate - MySql.
When I was testing the application I noticed the database connections were growing and growing.
I figured out that the entitymanager did not close the connections.
The problem was in this line of code :
EntityManagerFactory emf = Persistence.createEntityManagerFactory("databasename");
I was using this code in a function. It created a EntityManagerFactory at each execution of the function.
The solution was creating a singleton which needs to check if there already is an instance of the EntityManagerFactory. If there was an instance I needed to grab the instance instead of creating an new EntityManagerFactory.
The full explanation I found on this blog :
http://javanotepad.blogspot.com/2007/05/jpa-entitymanagerfactory-in-web.html
Posted on 30 Dec 2010 by Tommie
Deprecated: Function eregi() is deprecated in /home/webworx/public_html/cutenews/inc/shows.inc.php on line 766
Content Management Powered by CuteNews

