title: "Aquisition Attempt Failed" exception in logs with no effect on the application (Setup: Hibernate + c3p0)
body: <p>Ok, I got a weird one here. I have a application set up that is using hibernate configured for multi tenancy and C3P0 for connection pooling.</p>
  
  <p>Everthing works fine except that in my logs an exception is thrown and i cannct get to the cause of it... The weird thing is that this exception is in no way bothering my Application it is just working fine even with the exception being thrown (always 4 times and even if I do nothing but start the server and wait. After some seconds they pop up in the log and that is it)</p>
  
  <p>Here is the exception and some basic config that might be useful:</p>
  
  <pre><code>2013-05-28 09:06:02 WARN  BasicResourcePool:1841 - com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1d926e41 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 
  com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'dbuser'. ClientConnectionId:07fa33fd-9de8-4235-b991-ac7e9e1ad437
      at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
      at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:254)
      at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:84)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2908)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:2234)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:2220)
      at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1326)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
      at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
      at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
      at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
      at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
      at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
      at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
      at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
  </code></pre>
  
  <p>sessionFactory:</p>
  
  <pre><code>&lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
      &lt;property name="annotatedClasses"&gt;
          &lt;list&gt;
              ...
          &lt;/list&gt;
      &lt;/property&gt;
      &lt;property name="hibernateProperties"&gt;
          &lt;value&gt;
              hibernate.multiTenancy=SCHEMA
              hibernate.tenant_identifier_resolver=xxx.xxx.hibernate.CurrentTenantIdentifierResolverImpl
              hibernate.multi_tenant_connection_provider=xxx.xxx.hibernate.MultiTenantConnectionProviderImpl
  
              hibernate.dialect=${hibernate.dialect}
              hibernate.use_sql_comments=${hibernate.debug}
              hibernate.show_sql=${hibernate.debug}
              hibernate.format_sql=${hibernate.debug}
          &lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>The c3p0-config.xml:</p>
  
  <pre><code>&lt;c3p0-config&gt; 
      &lt;named-config name="c3p0name"&gt;  
          &lt;property name="acquireIncrement"&gt;3&lt;/property&gt;
          &lt;!--property name="automaticTestTable"&gt;con_test&lt;/property--&gt; 
          &lt;property name="checkoutTimeout"&gt;30&lt;/property&gt; 
          &lt;property name="idleConnectionTestPeriod"&gt;30&lt;/property&gt; 
          &lt;property name="initialPoolSize"&gt;2&lt;/property&gt; 
          &lt;property name="maxIdleTime"&gt;18000&lt;/property&gt; 
          &lt;property name="maxPoolSize"&gt;30&lt;/property&gt; 
          &lt;property name="minPoolSize"&gt;2&lt;/property&gt; 
          &lt;property name="maxStatements"&gt;50&lt;/property&gt;
          &lt;property name="testConnectionOnCheckin"&gt;true&lt;/property&gt;
      &lt;/named-config&gt;
  &lt;/c3p0-config&gt;
  </code></pre>
  
  <p>Here is the implementation that instantiates the ConnectionPool:</p>
  
  <pre><code>public class MultiTenantConnectionProviderImpl implements MultiTenantConnectionProvider  {
  
  
      private static final long serialVersionUID = 8074002161278796379L;
  
      ComboPooledDataSource cpds;
  
      public MultiTenantConnectionProviderImpl() throws PropertyVetoException {
          cpds = new ComboPooledDataSource("c3p0name");
          cpds.setDriverClass("jdbc.driver"));
          cpds.setJdbcUrl("jdbc.url"));
          cpds.setUser("dbuser");
          cpds.setPassword("dbuserpassword"));
      }
  
  
      @Override
      public Connection getAnyConnection() throws SQLException {
          return cpds.getConnection();
      }
  
      @Override
      public Connection getConnection(String dbuser) throws SQLException {
          return cpds.getConnection(dbuser, PropertyUtil.getCredential(dbuser));
      }
  </code></pre>
  
  <p>Even if there is no direct answer available I am happy with any remark or direction that might help my investigation, so just post anything you got. Thank you in advance</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I found the error at hand for the failing initial connections it was just a misconfiguration of the dbuserpassword for the passwordproperty of the DBConnectionPool....</p>
  
  <p>This solves part of the question and leaves ony the duplicate initaly which if following the discussion below the answer from @Steve Waldman  is most likely just a log4j misconfiguration.</p>