How to disable hibernation pooling

I have a web application that is currently using C3P0 and Hibernate to connect to a Firebird 1.5 database.

I run into an issue from time to time where the database just stops responding, even trying to manually restart the service has no effect and it doesn't generate any logs, so I need to manually WRITE the machine to get it working again.

I think maybe Firebird hangs when the pool tries to get a certain number of connections or something. So I need to test my application without connection pooling to check if this is not a problem or not.

I can't just remove the C3P0 config from persistence state, because this hibernate mode will use its own built-in connection pool. So how do you do it?

+3


source to share


2 answers


The most flexible solution is to use an explicit DataSource instead of setting up a connection pool through Hibernate. One of the configuration options for the non-union DataSource

is to use DriverManagerDataSource :

@Override
protected Properties getProperties() {
    Properties properties = new Properties();
    properties.put("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
    //log settings
    properties.put("hibernate.hbm2ddl.auto", "update");
    //data source settings
    properties.put("hibernate.connection.datasource", newDataSource());
    return properties;
}

protected ProxyDataSource newDataSource() {
    DriverManagerDataSource actualDataSource = new DriverManagerDataSource();
    actualDataSource.setUrl("jdbc:hsqldb:mem:test");
    actualDataSource.setUsername("sa");
    actualDataSource.setPassword("");
    ProxyDataSource proxyDataSource = new ProxyDataSource();
    proxyDataSource.setDataSource(actualDataSource);
    proxyDataSource.setListener(new SLF4JQueryLoggingListener());
    return proxyDataSource;
}

      

Thus, you can choose to join or not join DataSource

.



To better understand your connection pool resource usage, you can configure FlexyPool to collect metrics for:

  • parallel connections
  • concurrent connection requests
  • time to connect to data source
  • communication lease time
  • maximum pool size
  • total connection time
  • overflow pool size
  • retry attempts
0


source


I found the documentation for hibernate 3.3 and 4.3 that says:

Just replace the hibernate.connection.pool_size property with your specific connection pool settings. This will disable Hibernate's internal pool.

Hibernate will use its org.hibernate.connection.C3P0ConnectionProvider for pooling if you set hibernate.c3p0. * properties



So remove hibernate.connection.pool_size and any hibernate.c3p0 ... properties from the config, which disables pooling.

0


source







All Articles