I have a problem with the open connections in the database, where an error is occurring if the application tries to create more connections than the limit. Assuming that the application creates and closes the connections for each interaction in the database (insert / update / select), how to make the application wait for a new connection? I am using hibernate + java. / p>
EntityManagerFactory factory = Persistence.createEntityManagerFactory("model");
EntityManager manager = factory.createEntityManager();
manager.getTransaction().begin();
manager.persist(produto);
manager.getTransaction().commit();
manager.close();
factory.close();
Edit
I took a look at SessionFactory
, I configured the application to use the Connection Pool hibernate.cfg.xml
, but the error still occurs.
HibernateUtils.java
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
Here the method of recording
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
session.save(produto);
session.getTransaction().commit();
hibernate.cfg.xml
<!-- Pool de conexão -->
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.max_size">4</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<!-- entidade mapeada -->
<mapping class="br.com.sales.model.ProdutosVO" />