Hi,
I have a JSF application that is using hibernate to persist data to a MySQL database, but after doing a few small operations in the application I get the error:
com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections"
A google search quickly showed me that this is a pretty common error when working with database connections, but I'm yet to find a real solution.
The application is running on Tomcat 5.5.x using Hibernate 3.x to persist to a MySQL 5.x database.
For one, I thought that I might have a connection leak somewhere in the application, but the session.close() is called every time I finish an operation. Are there any particular methods I might be able to call to prevent this?
I see that there is a way to increase the maximum connections to the mysql databse. Does anyone know how this is done? (I'm running under OS X) I'm hoping that this might solve the problem, though I wouldn't be sure how much to increase to.
I am not using any connection pooling, which from what I understand might be a big help in this situation by recycling the connections. What are the steps to take to implement connection pooling in a JSF application? Is connection pooling more or less necessary in a proper web app or is it simply recommended in heavy use situations?
Also, I am not using a helper class to open connections, could this be an issue at all? What are the advantages to using such a class? The reason I haven't yet is just to keep things simple, but if there's nothing to lose I feel I should just go for it. Are there any examples of such a class on the internet I should use? so far, a typical save operation of mine looks like this:
Code:
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.saveOrUpdate(estInitObj);
tx.commit();
session.close();
I'm quite puzzled on this issue.
Any help is greatly appreciated.