title: Adding c3p0 to spring hibernate project
body: <p>I had some trouble with connection timeouts. Problem: After mysql timeout hibernate stops working. It seams to work fine, but it does not write further data to database. After searching the logs, I found the hint: last connection 53000 seconds - connection problem. Timeout is mysql-default (28000). So I tried increasing mysql timeout, but won't use in production system.</p>
  
  <p>Searching for a better solution, I found out, that probably c3p0 could solve my problem with a test query.</p>
  
  <p>I am using hibernate with spring. That's were trouble starts. I added c3p0 as DataSource (Bean):</p>
  
  <pre><code>&lt;bean id="dataSource_archiv" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"&gt;
      &lt;property name="driverClass" value="${hibernate.connection.driver_class}" /&gt;
      &lt;property name="jdbcUrl" value="${hibernate.connection.url}" /&gt;
      &lt;property name="user" value="${hibernate.connection.username}" /&gt;
      &lt;property name="password" value="${hibernate.connection.password}" /&gt;
      &lt;property name="minPoolSize" value="${hibernate.connection.minPoolSize}" /&gt;
      &lt;property name="maxPoolSize" value="${hibernate.connection.maxPoolSize}" /&gt;
      &lt;property name="maxIdleTime" value="${hibernate.connection.maxIdleTime}" /&gt;
      &lt;property name="maxStatements" value="${hibernate.connection.maxStmts}" /&gt;
      &lt;property name="testConnectionOnCheckout" value="${hibernate.connection.testCo}" /&gt;
      &lt;property name="testConnectionOnCheckin" value="${hibernate.connection.testCo}" /&gt;
      &lt;property name="preferredTestQuery" value="${hibernate.connection.testSQL}" /&gt;
      &lt;property name="idleConnectionTestPeriod" value="${hibernate.connection.testPeriod}" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p><a href="https://gist.github.com/anonymous/cf6461fc6bc6b8592b39" rel="nofollow">Complete hibernate Config File.</a></p>
  
  <p>But afterwards, the application cannot be started anymore:</p>
  
  <pre><code> Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appConfig': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field
  </code></pre>
  
  <p><a href="https://gist.github.com/anonymous/abc9f8d93d224e320f33" rel="nofollow">Complete Stack trace.</a></p>
  
  <p>So probably I misconfigured something. Where  can I start analyzing the problem?</p>
  
  <p>Or is there any other good solution? Like starting a Native SQL from hibernate to keep connection alive? I would prefer the solution with c3p0.</p>
  
  <p>Thanks.</p>