سؤال

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.

هل كانت مفيدة؟

المحلول

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();
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top