Here's what I understood from reading the source code:
- I have a standalone application
- when I first connect to the db, Hibernate updates the database using SchemaUpdate from SessionFactoryImpl. This schema update is created using the SchemaUpdate(cfg, settings) constructor, which
doesn't instantiate a new ConnectionProvider but uses the one from the settings
Code:
public SchemaUpdate(Configuration cfg, Settings settings) throws HibernateException {
this.configuration = cfg;
dialect = settings.getDialect();
connectionProvider = settings.getConnectionProvider();
exceptions = new ArrayList();
}
- when SchemaUpdate is done, it closes the ConnectionProvider, which cannot be used afterwards
- afterwards, when I try to do something on the database, it appears the (closed) connection provider from the settings is used and it explodes...
Code:
11:52:45.217 DEBUG [main] org.hibernate.util.JDBCExceptionReporter - Cannot open connection [???]
java.sql.SQLException: com.mchange.v2.c3p0.PoolBackedDataSource@11d329d [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@16c1bce [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 16c1bce, idleConnectionTestPeriod -> 3600, initialPoolSize -> 0, maxIdleTime -> 100, maxPoolSize -> 20, maxStatements -> 50, maxStatementsPerConnection -> 0, minPoolSize -> 0, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@1d50fd2 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 1d50fd2, jdbcUrl -> jdbc:derby:Producer_db;create=true, properties -> {user=******, password=******} ], preferredTestQuery -> null, propertyCycle -> 300, testConnectionOnCheckin -> true, testConnectionOnCheckout -> false, usesTraditionalReflectiveProxies -> false ], factoryClassLocation -> null, identityToken -> 11d329d, numHelperThreads -> 3 ] has been closed() -- you can no longer use it.
(right now, we're envisioning a temporary locally patched SessionFactoryImpl where we use the old SchemaUpdate(cfg,connectionProperties) constructor)
Code:
public SchemaUpdate(Configuration cfg, Properties connectionProperties) throws HibernateException {
this.configuration = cfg;
dialect = Dialect.getDialect(connectionProperties);
Properties props = new Properties();
props.putAll( dialect.getDefaultProperties() );
props.putAll(connectionProperties);
connectionProvider = ConnectionProviderFactory.newConnectionProvider(props);
exceptions = new ArrayList();
}