Hibernate version: 3.2
Name and version of the database you are using: MySql 5.1
Hello! I am stuck!
I try to configure c3p0 connection pooling.
So I have in hibernate.cfg.xml:
Code:
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="c3p0.max_size">20</property>
Then, in my application, I have to create a session factory for each one of number of databases I have:
Code:
for (String dbname: ...) {
Configuration cfg = new AnnotationConfiguration().configure("hibernate_rpx.cfg.xml");
cfg.setProperty("hibernate.connection.url", "jdbc:mysql://"+dbname);
SessionFactory sf = cfg.buildSessionFactory();
sessionFactories.put(app, sf);
}
So far so good. The problem is that during the buildSessionFactory method, a large amount of initial connections are established - like 100 per a database. So soon the maximum number of connections to the database server is exausted.
I think that the number of connection is related to the number of annotated classes - since when there are only 2 classes, only 4 connections are created. As if each DDL statement (updating db model) is causing many new connections to be created.
Debug info from c3p0:
[System][INFO ] Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@1159e0c [ connectionPoolDataSource ->
com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@1b1ab1d [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquir
eRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkout
Timeout -> 0, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> nul
l, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1b1ab1d, idleConnectionTestPeriod -> 0, initialPoolSize
-> 1, maxIdleTime -> 0, maxPoolSize -> 20, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 1, nested
DataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@1e2f6b0 [ description -> null, driverClass -> null, factoryCla
ssLocation -> null, identityToken -> 1e2f6b0, jdbcUrl -> jdbc:mysql://localhost/rpx, properties -> {user=******, passwor
d=******, server=localhost} ], preferredTestQuery -> null, propertyCycle -> 300, testConnectionOnCheckin -> false, testC
onnectionOnCheckout -> false, usesTraditionalReflectiveProxies -> false ], factoryClassLocation -> null, identityToken -
> 1159e0c, numHelperThreads -> 3 ]
Have anyone else had such situation? Any help would be appreciated.