I am using hibernate in a JSP application deployed in Tomcat.
I currently have the following pool configuration:
C3P0 parameters:
<property name="hibernate.c3p0.min_size">2</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_statements">50</property>
Code between sessionFactory.openSession() and session.close():
Code:
try
{
_currentSession.beginTransaction();
Query allItems = _currentSession.createQuery(query);
list = allItems.list();
_currentSession.getTransaction().commit();
}
catch (HibernateException e) {
_currentSession.getTransaction().rollback();
SQLException sqlexc = new SQLException();
sqlexc.setStackTrace(e.getStackTrace());
throw new DataException(e.getMessage(),sqlexc);
}
finally
{
flushSession();
releaseResources();
}
where the flush and releaseresources methods are:
Code:
private void flushSession()
{
try
{
if(_currentSession != null)
{
_currentSession.flush();
}
}
catch (HibernateException e) {
// TODO: handle exception
}
}
public void releaseResources() {
try {
if (_currentSession != null) {
//_currentSession.connection().close();
_currentSession.close();
flushSession();
_currentSession = null;
}
} catch (HibernateException e) {
// TODO: handle exception
}
}
My problem is that, having a look at the postgres processes created (for example in PgAdminIII, I see that, for each call of this query, I get one to three processes with
Current Query - <IDLE>
I am confused and don't understand what's happening - isn't the connection pool supposed to reuse connections instead of creating new ones? It seems these Idle processes just accumulate forever.
Any help greatly appreciated.