title: entitymanager.close() not closing connections to database
body: <p>I'm developing a quiz system and I'm new to JPA &amp; Hibernate. I've used hibernate 4.2.3 and I've used c3p0 connection pooling.
  Code works fine but each EntityManager creates a connection which is never closed. And once the max number of connections are reached then application can't access database.
  I'm using MySQL 5.6.10, when I see connections in workbench I never see connections being destroyed. And application is not reusing the connections.</p>
  
  <p>My guess is that connections are not returned to connection pool. I dunno how as i have written "manager.close()".</p>
  
  <p>The same happens with hibernate internal connection pooling. (In case i remove c3p0.)</p>
  
  <p>Here are the properties of "persistence.xml"</p>
  
  <pre><code>&lt;property name="hibernate.connection.provider_class" value="org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider" /&gt;
  &lt;property name="hibernate.c3p0.max_size" value="10" /&gt;
  &lt;property name="hibernate.c3p0.min_size" value="2" /&gt;
  &lt;property name="hibernate.c3p0.acquire_increment" value="1" /&gt;
  &lt;property name="hibernate.c3p0.idle_test_period" value="5000" /&gt;
  &lt;property name="hibernate.c3p0.max_statements" value="20" /&gt;
  &lt;property name="hibernate.c3p0.timeout" value="500" /&gt;
  </code></pre>
  
  <p>Here is how i access EntityManagerFactory</p>
  
  <pre><code>public class EntityMangFactory {
  
      private static EntityManagerFactory emf=null;
  
      private static void initEntityManagerFactory()
      {
          emf=Persistence.createEntityManagerFactory("com.oes.jpa");  //persistence-unit-name//
  
      }
  
      public static EntityManagerFactory getEntityManagerFactory()
      {
          if(emf==null){
              initEntityManagerFactory();
          }
          return emf;
      }
  
  
  }
  </code></pre>
  
  <p>Here is how i access the database.</p>
  
  <pre><code>public static List&lt;MarksDTO&gt; getMarks(int id){
  
          EntityManagerFactory factory= EntityMangFactory.getEntityManagerFactory();
          EntityManager manager= factory.createEntityManager();
          manager.getTransaction().begin();
          TypedQuery&lt;MarksDTO&gt; q= manager.createQuery("select new com.examsystem.DTO.MarksDTO(m.courseId,m.score,m.setNo,m.courseName) from MarksBean as m where TraineeID=:TraineeID",MarksDTO.class);
          q.setParameter("TraineeID", id);
          List&lt;MarksDTO&gt; ls=q.getResultList();
  
  
          manager.close();
  
          return ls;
      }
  </code></pre>
  
  <p>Please point me to where I'm wrong.</p>
  
  <p>Thanks in advance.</p>