문제

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