java - Entitymanager, too many connections -
i create 1 session factory whole progamm , create everytime want persist/update/query smth. new entity manager many connection error. can give me adivce? in point of view cant best solution increase number of allowed connections in mysql. used c3p0 pooling.
try using try-catch-finally template whenever calling entitymanager
.
entitymanager em = ... //however em. try { em.gettransaction().begin(); // ... put persistence code here. em.gettransaction().commit(); } catch (exception ex) { em.gettransaction().rollback(); throw ex; } { em.close(); }
Comments
Post a Comment