title: Transaction started but not ended on database test connection query
body: <p>Recently a bug was noticed in our application which caused the time of the operation to differ from the actual time(we are using current_timestamp() PostgreSQL function instead of passing time from the code). We've looked into it and discovered that the problem had to with some transaction which was starting and was never ended.</p>
  
  <p>The application uses Spring's <code>DataSourceTransactionManager</code> which does it job perfectly (every transactional operations are being concluded as expected). Now, the problem seems to be coming from our connection pool lib(BoneCP). We have configured <code>SELECT 1</code> query to check database connectivity. And what is actually shown in PostgreSQL log is the following:</p>
  
  <pre><code>LOG: execute S_1: BEGIN
  LOG: execute &lt;unnamed&gt;: SELECT 1
  LOG: execute S_1: BEGIN
  LOG: execute &lt;unnamed&gt;: SELECT 1
  </code></pre>
  
  <p>No COMMIT is following any of the connection test statement (further log shows no more BEGIN commands before SELECT 1, but I guess it is because that connection cannot start new transaction while one is already active..</p>
  
  <p>I am wondering if it is some bug or what might be wrong? </p>
  
  <p>Here is servlet-context configuration part file(only posting relevant parts):</p>
  
  <pre><code>&lt;bean id="ds" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close"&gt;
      &lt;property name="idleConnectionTestPeriodInMinutes" value="5"/&gt;
      &lt;property name="idleMaxAgeInMinutes" value="30"/&gt;
      &lt;property name="lazyInit" value="true"/&gt;
      &lt;property name="maxConnectionsPerPartition" value="95"/&gt;
      &lt;property name="minConnectionsPerPartition" value="1"/&gt;
      &lt;property name="partitionCount" value="3"/&gt;
      &lt;property name="acquireIncrement" value="5"/&gt;
      &lt;property name="statementsCacheSize" value="100"/&gt;
      &lt;property name="releaseHelperThreads" value="3"/&gt;
      &lt;property name="defaultAutoCommit" value="false"/&gt;
      &lt;property name="connectionTestStatement" value="SELECT 1;"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="sql" class="groovy.sql.Sql"&gt;
      &lt;constructor-arg ref="dsProxy"/&gt;
  &lt;/bean&gt;
  
  &lt;tx:annotation-driven transaction-manager="txManager" proxy-target-class="true"/&gt;
  
  &lt;bean id="dsProxy" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy"&gt;
      &lt;constructor-arg ref="fooDSProxy"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="fooDSProxy" class="org.something.Foo" factory-method="createProxy"&gt;
      &lt;constructor-arg ref="ds"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;
      &lt;property name="dataSource" ref="dsProxy"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Where <code>org.something.Foo</code> has nothing special, used for logging purposes.</p>
  
  <p>Any help appreciated.</p>