Hibernate C3P0 Connection Pool

In a Spring project that includes Hibernate, you'll typically see a BasicDataSource being setup in the applicationContext.xml
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">

For testing, this is fine, but this is not ideal for production since it will create a new connection to the database for every query you run.
A better approach is obviously keeping a set number of connections open and reusing them. The performance benefit of a connection pool is huge, especially if the database is sitting on a remote server.

In your pom.xml, add the following dependency:
I see C3P0 has been moved to here.

In your applicationContext.xml, replace the BasicDataSource with the C3P0 Connection Pool:
<bean class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" id="dataSource">
    <property name="driverClass" value="${database.driverClassName}" />
    <property name="jdbcUrl" value="${database.url}" />
    <property name="user" value="${database.username}" />
    <property name="password" value="${database.password}" /> 			

    <property name="acquireIncrement" value="1" />
    <property name="acquireRetryDelay" value="200" />
    <property name="acquireRetryAttempts" value="5" />
    <property name="minPoolSize" value="5" />
    <property name="initialPoolSize" value="10" />
    <property name="maxPoolSize" value="15" />
    <property name="maxIdleTime" value="1800" />
    <property name="idleConnectionTestPeriod" value="10" />
    <property name="preferredTestQuery" value="SELECT 1" />
    <property name="checkoutTimeout" value="40" />
That's it, you now have a connection pool that will automatically reconnect as soon as you kill a connection or retry a query if it failed due to connectivity issues.

Something else you can look at is enabling auto-close sessions in your persistence.xml:
<property name="hibernate.auto_close_sesions" value="true"/>