title: Hibernate startup very slow
body: <p>For some reason, the startup of my hibernate application is unbarrably slow. (up to 2 min)
  I have been thinking that the c3p0 configuration is plain wrong (<a href="https://stackoverflow.com/questions/14417692/initializing-c3p0-connection-pool-takes-2-min" title="related question">related question</a>) but studying the logs shows, that there is no activity just after the connection to the server is established. Also, using the built-in polling capabilities of Hibernate shows the same result.</p>
  
  <p>Here is a snippet from the logs:</p>
  
  <pre><code>20:06:51,248 DEBUG BasicResourcePool:422 - decremented pending_acquires: 0
  20:06:51,248 DEBUG BasicResourcePool:1644 - trace com.mchange.v2.resourcepool.BasicResourcePool@1acaf0ed [managed: 3, unused: 2, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@5f873eb2)
  20:06:51,248 DEBUG BasicResourcePool:1644 - trace com.mchange.v2.resourcepool.BasicResourcePool@1acaf0ed [managed: 3, unused: 2, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@5f873eb2)
  20:06:51,273 DEBUG JdbcServicesImpl:121 - Database -&gt;
         name : PostgreSQL
      version : 9.1.6
        major : 9
        minor : 1
  20:06:51,274 DEBUG JdbcServicesImpl:127 - Driver -&gt;
         name : PostgreSQL Native Driver
      version : PostgreSQL 9.2 JDBC4 (build 1002)
        major : 9
        minor : 2
  20:06:51,274 DEBUG JdbcServicesImpl:133 - JDBC version : 4.0 ##### HANGS FOR 2 MINUTES  ON THIS LINE #####
  20:08:14,727  INFO Dialect:123 - HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
  20:08:14,736  INFO LobCreatorBuilder:120 - HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
  20:08:14,736 DEBUG GooGooStatementCache:297 - checkinAll(): com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 0; checked out: 0; num connections: 0; num keys: 0
  20:08:14,736 DEBUG GooGooStatementCache:297 - checkinAll(): com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 0; checked out: 0; num connections: 0; num keys: 0
  20:08:14,883 DEBUG BasicResourcePool:1644 - trace com.mchange.v2.resourcepool.BasicResourcePool@1acaf0ed [managed: 3, unused: 2, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@5f873eb2)
  20:08:14,883 DEBUG BasicResourcePool:1644 - trace com.mchange.v2.resourcepool.BasicResourcePool@1acaf0ed [managed: 3, unused: 2, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@5f873eb2)
  20:08:14,883 DEBUG GooGooStatementCache:297 - checkinAll(): com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 0; checked out: 0; num connections: 0; num keys: 0
  </code></pre>
  
  <p>(Please mind the #comment#.)</p>
  
  <p>I also tried an older Postgres JDBC Driver with no luck whatsoever.</p>
  
  <p>Connecting to a local Database works just fine. Connection is established immediately and I can query the database. This remote db is a Heroku dev instance. I tried it with another remote as well. Same outcome.</p>
  
  <p>I'm out of ideas what I can check now to get rid of this annoyance. Any help would be much appreciated.</p>
  
  <p>Maybe my hibernate.cfg.xml is helpful:</p>
  
  <p>
  http://www.hibernate.org/dtd/hibernate-</p>
  
  <pre><code>configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt;
          &lt;property name="connection.url"/&gt;
          &lt;property name="connection.default_schema"/&gt;
          &lt;property name="connection.username"/&gt;
          &lt;property name="connection.password"/&gt; 
  
          &lt;property name="dialect"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/property&gt;
              &lt;property name="cache.provider_class"&gt;org.hibernate.cache.internal.NoCacheProvider&lt;/property&gt;
          &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;            
          &lt;property name="hibernate.c3p0.acquire_increment"&gt;3&lt;/property&gt;
          &lt;property name="hibernate.c3p0.min_size"&gt;3&lt;/property&gt;
          &lt;property name="hibernate.c3p0.max_size"&gt;10&lt;/property&gt;
          &lt;property name="hibernate.c3p0.timeout"&gt;300&lt;/property&gt;
          &lt;property name="hibernate.c3p0.max_statements"&gt;50&lt;/property&gt;
          &lt;property name="hibernate.c3p0.idle_test_period"&gt;3000&lt;/property&gt;
          &lt;property name="hibernate.c3p0.acquireRetryDelay"&gt;500&lt;/property&gt;
  
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
          &lt;property name="format_sql"&gt;false&lt;/property&gt;
  
          &lt;property name="hbm2ddl.auto"&gt;validate&lt;/property&gt;
  
          &lt;mapping class="core.entities.Exam" /&gt;
          &lt;mapping class="core.entities.Examination" /&gt;
          ...
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>EDIT: I tried to find the reason for the delay via logs and profiling but have been widely unsuccessful with it. (I'm not that advanced in this area though.) In the end I did go with try and fail and changed my db for a remote MySQL instance to check if any difference occurs. Turns out, that the connection is established nearly immediately.</p>