-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Too Many Connections!
PostPosted: Tue Jul 17, 2007 9:06 am 
Newbie

Joined: Thu Jul 12, 2007 8:57 am
Posts: 11
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.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 17, 2007 10:57 am 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Connection pooling is essential to performance in a multiuser webapp. Tomcat provides this feature through Apache DBCP (look in Tomcat docs). It will bind the DataSource to JNDI and you can have Hibernate lookup the DataSource that way:
http://www.hibernate.org/hib_docs/v3/re ... ionfactory

Look at Table 3.2. All you should need is hibernate.connection.datasource in your properties once you've setup the DataSource in Tomcat.

Happy Hibernating.

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.