title: Tomcat slow startup due to hibernate
body: <p>Currently using Tomcat 6 and hibernate 3 for my application but I notice the startup is very slow,I only have about 40 entities mapped. Not sure if this is caused by hibernate the logs are below:</p>
  
  <p>It takes around 5 mins for the below: </p>
  
  <p>Any ideas? btw I have already tried increasing tomcat memory</p>
  
  <pre><code>2016-03-01 09:18:53,933  INFO [main] SessionFactoryObjectFactory.addInstance(105) | Not binding factory to JNDI, no JNDI name configured
  2016-03-01 09:24:42,046 DEBUG [main] GnrlLookupView.&lt;clinit&gt;(37) | Registering view: GnrlLookupView
  2016-03-01 09:24:46,881  INFO [main] QuartzScheduler.&lt;init&gt;(209) | Quartz Scheduler v.1.6.0 created.
  </code></pre>
  
  <p>Hibernate config:</p>
  
  <pre><code>&lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
      &lt;property name="dataSource"&gt; &lt;ref bean="dataSource" /&gt; &lt;/property&gt;
      &lt;property name="mappingJarLocations"&gt;
          &lt;list&gt;
              &lt;value&gt;WEB-INF/lib/*-hbm.jar&lt;/value&gt;
          &lt;/list&gt; 
      &lt;/property&gt;
      &lt;property name="lobHandler"&gt;
          &lt;bean class="org.springframework.jdbc.support.lob.OracleLobHandler"&gt;
              &lt;property name="nativeJdbcExtractor"&gt;
                  &lt;bean class="org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor" /&gt;
              &lt;/property&gt;
          &lt;/bean&gt;
      &lt;/property&gt;     
      &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.Oracle10gDialect&lt;/prop&gt;
              &lt;prop key="hibernate.connection.SetBigStringTryClob"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.cache.use_second_level_cache"&gt;true&lt;/prop&gt;  &lt;!-- Explicitly enabled 2nd level cache since upgrade to hibernate version 3.2.x --&gt;
              &lt;prop key="hibernate.cache.use_query_cache"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.cache.provider_class"&gt;org.hibernate.cache.EhCacheProvider&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  
      &lt;property name="entityInterceptor"&gt;
          &lt;ref bean="entityAuditInterceptor" /&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) --&gt; 
  &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory"&gt;
          &lt;ref local="sessionFactory" /&gt;
      &lt;/property&gt;
  &lt;/bean&gt;ref bean="entityAuditInterceptor" /&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) --&gt; 
  &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory"&gt;
          &lt;ref local="sessionFactory" /&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p><strong>UPDATE</strong>: I've enabled finer logging and came to the below, it prints out the below for 5 mins, any idea?</p>
  
  <pre><code>SessionFactoryUtils.doGetSession(316) | Opening Hibernate Session
  2016-03-01 10:46:45,468 DEBUG [main] OracleLobHandler.getClobAsString(229) | Returning Oracle CLOB as string
  2016-03-01 10:46:45,468 DEBUG [main] OracleLobHandler.getClobAsString(229) | Returning Oracle CLOB as string
  2016-03-01 10:46:45,468 DEBUG [main] OracleLobHandler.getClobAsString(229) | Returning Oracle CLOB as string
  2016-03-01 10:46:45,483 DEBUG [main] OracleLobHandler.getClobAsString(229) | Returning Oracle CLOB as string
  2016-03-01 10:46:45,483 DEBUG [main] OracleLobHandler.getClobAsString(229) | Returning Oracle CLOB as string
  2016-03-01 10:46:45,483 DEBUG [main] OracleLobHandler.getClobAsString(229) | Returning Oracle CLOB as string
  
  2016-03-01 10:44:43,487 DEBUG [main] HibernateTemplate.flushIfNecessary(389) | Eagerly flushing Hibernate session
  2016-03-01 10:44:43,487 DEBUG [main] SessionFactoryUtils.closeSession(789) | Closing Hibernate Session
  2016-03-01 10:44:43,487 DEBUG [main] SessionFactoryUtils.doGetSession(316) | Opening Hibernate Session
  </code></pre>