title: C3P0 Throws Exception in case of @transactional
body: <p>Hi I am using <code>Hibernate core 4.3.1 FINAL</code>, <code>hibernate-c3p0 4.3.1 FINAL</code>. Using JPA persistence configuration which is as below.</p>
  
  <pre><code>&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
  version="2.0"&gt;
  
  &lt;persistence-unit name="somename"&gt;
      &lt;description&gt;
  
      &lt;/description&gt;
  
      &lt;properties&gt;
          &lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /&gt;
          &lt;property name="javax.persistence.jdbc.url"
              value="jdbc:mysql://localhost:3306/somename?autoReconnect=true" /&gt;
          &lt;property name="javax.persistence.jdbc.user" value="root" /&gt;
          &lt;property name="javax.persistence.jdbc.password" value="admin" /&gt;
  
          &lt;property name="hibernate.show_sql" value="true" /&gt;
          &lt;property name="hibernate.hbm2ddl.auto" value="none" /&gt;
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" /&gt;
          &lt;property name="hibernate.connection.provider_class" value="org.hibernate.c3p0.internal.C3P0ConnectionProvider" /&gt;
  
          &lt;property name="hibernate.c3p0.max_size" value="100" /&gt;
          &lt;property name="hibernate.c3p0.min_size" value="1" /&gt;
          &lt;property name="hibernate.c3p0.acquire_increment" value="1" /&gt;
          &lt;property name="hibernate.c3p0.idle_test_period" value="50" /&gt;
          &lt;property name="hibernate.c3p0.max_statements" value="0" /&gt;
          &lt;property name="hibernate.c3p0.timeout" value="100" /&gt;
      &lt;/properties&gt;
  
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p></p>
  
  <p>I am using <code>JpaTransactionManager</code> by Spring like this.
      
          
      
      
          
      </p>
  
  <p>In my service class I have used.</p>
  
  <pre><code>@Transactional
  public void deleteSomething (){...}
  </code></pre>
  
  <p>So, whenever this method, or any method with transaction is executed, I get the following exception:</p>
  
  <pre><code>2015-03-01 02:34:16 [DEBUG] - delete from badoc where baId=? and docId=?
  Hibernate: delete from badoc where baId=? and docId=?
  2015-03-01 02:34:16 [DEBUG] - com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager@4b969e3c.acquireResource() returning. 
  2015-03-01 02:34:16 [DEBUG] - trace com.mchange.v2.resourcepool.BasicResourcePool@40873594 [managed: 2, unused: 1, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@6f5a9e8e)
  2015-03-01 02:34:16 [DEBUG] - decremented pending_acquires: 0
  2015-03-01 02:34:16 [DEBUG] - Acquisition series terminated successfully. Decremented pending_acquires [0],  attempts_remaining: 30
  2015-03-01 02:34:16 [DEBUG] - Converting Throwable to SQLException...
  java.lang.NullPointerException
      at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.maybeDirtyTransaction(NewProxyPreparedStatement.java:2520)
      at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.getMaxRows(NewProxyPreparedStatement.java:1403)
      at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.close(JdbcCoordinatorImpl.java:530)
      at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.release(JdbcCoordinatorImpl.java:407)
      at org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl.releaseStatements(AbstractBatchImpl.java:173)
      at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:76)
      at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:3400)
      at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:3624)
      at org.hibernate.action.internal.EntityDeleteAction.execute(EntityDeleteAction.java:113)
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:453)
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:345)
      at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)
      at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)
      at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1218)
      at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:421)
      at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
      at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:177)
      at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:77)
      at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:515)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:757)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:478)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:272)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)
      at com.pwc.atlas.service.DocumentService$$EnhancerBySpringCGLIB$$b0e32825.manageBADocument(&lt;generated&gt;)
      at com.pwc.atlas.rest.SolrController.manageBaDocuments(SolrController.java:463)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:690)
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:744)
  2015-03-01 02:34:16 [DEBUG] - Exception clearing maxRows/queryTimeout [You can't operate on a closed Statement!!!]
  2015-03-01 02:34:16 [DEBUG] - committed JDBC Connection
  2015-03-01 02:34:16 [DEBUG] - Closing JPA EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@1295e6d1] after transaction
  2015-03-01 02:34:16 [DEBUG] - Closing JPA EntityManager
  2015-03-01 02:34:16 [DEBUG] - HHH000420: Closing un-released batch
  2015-03-01 02:34:16 [DEBUG] - Releasing JDBC connection
  </code></pre>
  
  <p>The transaction completes but with this exception.</p>
  
  <p>I am pretty new to using JPA with hibernate with connection pooling. Could you please help if I am missing something in the configuration?</p>