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