-
1. Re: Non managed JPA EntityManager is broken.
ztiringer Apr 30, 2009 12:09 AM (in response to sherkan777)Most likely your method (sometimes) takes longer than a second to execute, and eventually you run out of allowed DB sessions...
Consult DBA to increase number of sessions or reduce execution frequency or optimize execution time
-
2. Re: Non managed JPA EntityManager is broken.
swd847 Apr 30, 2009 12:36 AM (in response to sherkan777)Are you actually creating the EntityManagerFactory every time the method is called? Or was that included just to show us how you are creating it?
-
3. Re: Non managed JPA EntityManager is broken.
sherkan777 Apr 30, 2009 8:25 AM (in response to sherkan777)Nop, EMF is created once. Its included here for example, but my EM is created every time on each execute at the method begin.
My method is executed each second in
synchronized(MyClass.class) {..}
block, so concurently executions are eliminated.
I think to check in tomcat activated connections, but don't know how to do it? Is any way to check it, or debug where new connection is created and another isn't closed? -
4. Re: Non managed JPA EntityManager is broken.
sherkan777 Apr 30, 2009 8:31 AM (in response to sherkan777)Here is My EMF factory class, shared for whole project:
public class EMController { public EMController() {} private static boolean initialised; private static EntityManagerFactory sguniAdmEMF; private static EntityManagerFactory sguniOneEMF; private static EntityManagerFactory sguniTwoEMF; public static EntityManagerFactory getEntityManagerFactory(int emf) { init(); switch (emf) { case (0) : return sguniAdmEMF; case (1) : return sguniOneEMF; case (2) : return sguniTwoEMF; } return null; } public static void init() { if (!initialised) { synchronized (EMController.class) { sguniAdmEMF = Persistence.createEntityManagerFactory("sguniAdmDatabase"); sguniOneEMF = Persistence.createEntityManagerFactory("sguniOneDatabase"); sguniTwoEMF = Persistence.createEntityManagerFactory("sguniTwoDatabase"); initialised = true; } } } public void destroy() { sguniAdmEMF.close(); sguniOneEMF.close(); sguniTwoEMF.close(); } public static EntityManager getEM(int em) throws RuntimeException { return getEntityManagerFactory(em).createEntityManager(); } }