Hello. Please help me, JPA 2.
The question is:
Suppose I have some class that works with the database. Different objects create it, use it, etc. So that there are not many "dead" connections, they should always be closed.
EntityManagerFactory emf = Persistence.createEntityManagerFactory("commonStorage"); EntityManager em = emf.createEntityManager(); // операции em.close(); emf.close();
But creating a new EntityManager
takes time. Maybe there is something that I missed? Maybe you need to use one EntityManagerFactory
for the whole application? Or other options.