title: overcome Hibernate 5 connection limit
body: <p>I'm making a RESTful service that communicates with a database, using Hibernate as an ORM.</p>
  
  <p>The problem I am facing is Hibernate's connection pool limit that throw the exception whenever I reach the limit.</p>
  
  <pre><code>Exception in thread "main" org.hibernate.HibernateException: The internal connection pool has reached its maximum size and no connection is currently available!
  </code></pre>
  
  <hr>
  
  <p>1) I have tried to set the maximum pool size in the <code>hibernate.cfg.xml</code> </p>
  
  <pre><code>&lt;property name="connection.pool_size"&gt;10&lt;/property&gt;
  </code></pre>
  
  <p>2) I have tried instead of opening a new Session every time, getting the current connection </p>
  
  <pre><code>public static Session getCurrentSession(){
          try{
              return sessionFactory.getCurrentSession();
          }
          catch(Exception e){
              try {
                  return sessionFactory.openSession();
              } catch (Exception e1) {
                  e1.printStackTrace();
              }
          }
   }
  </code></pre>
  
  <hr>
  
  <p>I always reach the <code>limit</code> eventually.</p>
  
  <p><strong><em>Is there a way to totally overcome that ?</em></strong></p>