Question

I create only one session factory for the whole progamm and create everytime i want to persist/update/query smth. an new entity manager but i get always an to many connection error. Can anybody give me an adivce? In my point of view it cant be the best solution to increase the number of allowed connections in MySql. I used C3P0 for pooling.

Était-ce utile?

La solution

Try using a try-catch-finally template like this whenever calling the EntityManager.

EntityManager em = ... //However you get an em.
try {
    em.getTransaction().begin();

    // ...  Put your persistence code here.

    em.getTransaction().commit();
} catch (Exception ex) {
    em.getTransaction().rollback();
    throw ex;
} finally {
    em.close();
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top