title: Java 1.5 JPA with Hibernate and H2 is slow to create the EntityManagerFactory
body: <p>I'm trying to test some of our DB layer in Junit.</p>
  
  <p>The problem I have is that Persistence.createEntityManagerFactory() takes > 200 seconds! Googling for H2, JPA, Hibernate in some combination with createEntityManagerFactory gives nothing useful.</p>
  
  <p>This is my test:</p>
  
  <pre><code>import static org.junit.Assert.assertTrue;
  
  import java.util.Date;
  
  import javax.persistence.EntityManager;
  import javax.persistence.EntityManagerFactory;
  import javax.persistence.Persistence;
  
  import org.junit.Test;
  
  public class MinimalSet {
      @Test
      public void TestNamedQuery() {
          Date startTime = new Date();
  
          EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("TestPersistence");
          EntityManager entityManager = entityManagerFactory.createEntityManager();
  
          Date endTime = new Date();
  
          // Did it take less than 10 seconds?
          assertTrue(((endTime.getTime() - startTime.getTime()) / 1000.0) &lt; 10.0);
      }
  }
  </code></pre>
  
  <p>This is my persistence.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"&gt;
      &lt;persistence-unit name="TestPersistence" transaction-type="RESOURCE_LOCAL"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.show_sql" value="true" /&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" /&gt;
              &lt;property name="hibernate.connection.url" value="jdbc:h2:mem:test" /&gt;
              &lt;property name="hibernate.connection.driver_class" value="org.h2.Driver" /&gt;
              &lt;property name="hibernate.connection.username" value="root" /&gt;
              &lt;property name="hibernate.connection.password" value="" /&gt;
              &lt;property name="hibernate.show_sql" value="true" /&gt;
              &lt;property name="hibernate.format_sql" value="false" /&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>I don't use any other config file (E.g. hibernate.cfg.xml).</p>
  
  <p>I'd appreciate any clue as to why that takes so long.</p>
  
  <p>Thanks.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>It has started running fast (&lt;2 seconds).
  So I'm thinking there was some event it was waiting for. Does any of this talk to the network?</p>