title: Persistence.createEntityManagerFactory() takes very long time to return
body: <p>I am using Hibernate 4.2, JPA 2.0 &amp; Postgres 9.2 </p>
  
  <p>The code gets stuck at <code>Persistence.createEntityManagerFactory("peristence_unit_name");</code></p>
  
  <p>On further investigation I found that Hibernate makes a call to <code>getTypeInfo()</code> method of <code>java.sql.DatabaseMetaData</code> class. This method tries to load metadata about every database object</p>
  
  <pre><code>/**
   * Perform the extraction
   *
   * @param metaData The JDBC metadata
   *
   * @return The extracted metadata
   */
  public static LinkedHashSet&lt;TypeInfo&gt; extractTypeInfo(DatabaseMetaData metaData) {
      LinkedHashSet&lt;TypeInfo&gt; typeInfoSet = new LinkedHashSet&lt;TypeInfo&gt;();
      try {
          ResultSet resultSet = metaData.getTypeInfo(); // &lt;&lt; Gets stuck here.
          try {
               ......
  </code></pre>
  
  <p>The code for <code>getTypeInfo()</code> is part of Postgers' JDBC drivers and it is indeed the driver thats taking time to execute the method (I loaded the driver source and tried following the trail). But since this problem did not occur in Hibernate 3.3 (which I was using earlier), I think, Hibernate 3.3 was not calling this method, but Hibernate 4.2 is.</p>
  
  <p>Is there a way to solve this problem? Note that the same setup with Hibernate 3.3 was working fine.</p>
  
  <p>Extra Info :
  What the driver is doing all this time:</p>
  
  <p>It first gets the list of database objects and then loops through the resultset to get metadata of each object. </p>
  
  <p>There are around 3000 objects in the DB (I have a very large data-set requiring many partition tables. Plus PostGIS has many objects of its own)</p>
  
  <p>It takes about 1 second per object lookup, so it takes about 3000 seconds to finish the call.</p>