Hi all,
I have a problem with connection pooling using C3P0, the problem is, after opening a hibernate session and some transaction the following exception will be thrown, it seems something wrong with c3p0.
if anyone had such experience please enlighten me on this issue.
Hibernate version: 3.2
Mapping documents: HBM files
Code in which I acquire the current session:
Code:
public static Session currentSession () {
Session s = (Session)session.get();
if (s == null) {
try {
s= sessionFactory.openSession();
s.connection().setAutoCommit(true);
session.set(s);
} catch (SQLException e) {
s.close() ;
return null ;
}
}
return s ;
}
Full stack trace of any exception that occurs:Code:
WARN BasicResourcePool com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask:1841 run - com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@ae525c -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: Data source rejected establishment of connection, message from server: "Too many connections"
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:990)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2544)
at com.mysql.jdbc.Connection.<init>(Connection.java:1474)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:264)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
!
!
Name and version of the database you are using:Mysql 4 Hibernate & c3p0 settings: (in hibernate.cfg.xml)Code:
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/otpwithebTracker?characterEncoding=utf8</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="show_sql">true</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.timeout">60</property>
Any help would be appreciated.