Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring configuration of C3P0 with Hibernate?

I have a Spring/JPA application with Hibernate as the JPA provider. I've configured a C3P0 data source in Spring via:

<bean id="myJdbcDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
      destroy-method="close">
  <!-- Connection properties -->
  <property name="driverClass" value="$DS{database.class}" />
  <property name="jdbcUrl" value="$DS{database.url}" />
  <property name="user" value="$DS{database.username}" />
  <property name="password" value="$DS{database.password}" />
  <!-- Pool properties -->
  <property name="minPoolSize" value="5" />
  <property name="maxPoolSize" value="20" />
  <property name="maxStatements" value="50" />
  <property name="idleConnectionTestPeriod" value="3000" />
  <property name="loginTimeout" value="300" />

I then specified this data source in the Spring entity manager factory as follows:

<bean id="myLocalEmf"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
      <property name="persistenceUnitName" value="myapp-core" />
      <property name="dataSource" ref="myJdbcDataSource" />
 </bean>

However, I recently noticed while browsing maven artifacts a "hibernate-c3p0". What is this? Is this something I need to use? Or do I already have this configured properly?

like image 368
HDave Avatar asked Jun 09 '10 03:06

HDave


People also ask

What is c3p0 in hibernate?

C3p0 is an open-source JDBC connection pooling library, with support for caching and reuse of PreparedStatements. Hibernate provides support for Java applications to use c3p0 for connection pooling with additional configuration settings.

What is hibernate c3p0 Min_size?

min_size This is the minimum number of JDBC connections that C3P0 keeps ready at all times. hibernate. c3p0. max_size This is the maximum number of connections in the pool.

What is hibernate c3p0 Idle_test_period?

Hibernate default: 0 , caching is disable. hibernate.c3p0.idle_test_period – idle time in seconds before a connection is automatically validated. Hibernate default: 0.

Which connection pool is best for hibernate?

C3P0 is an open source JDBC connection pool distributed along with Hibernate in the lib directory. Hibernate will use its org. hibernate.


2 Answers

The hibernate-c3p0.jar provides the class org.hibernate.connection.C3P0ConnectionProvider, a C3P0-based implementation of the Hibernate ConnectionProvider contract. You need this artifact when you want to use C3P0 as Hibernate's standalone connection pool (that you configure through the hibernate.cfg.xml file). Since you're using Spring, you don't need it.

like image 116
Pascal Thivent Avatar answered Oct 17 '22 22:10

Pascal Thivent


org.hibernate:hibernate-c3p0 looks like the module you would use if you were configuring Hibernate to use C3P0 directly.

You shouldn't need it assuming the configuration you posted works for you - does it?

like image 23
matt b Avatar answered Oct 17 '22 22:10

matt b