Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
5.4, 5.3.8
-
None
Description
On application start if more than one thread needs an entity manager more than one instance of EntityManagerFactory may be created.
This is undesirable, because EMF may use a connection pool and creating more than one instance will lead to too many open database connections.
EntityManagerSourceImpl.java:
public EntityManagerFactory getEntityManagerFactory(final String persistenceUnitName) { EntityManagerFactory emf = entityManagerFactories.get(persistenceUnitName); if (emf == null) { emf = createEntityManagerFactory(persistenceUnitName); entityManagerFactories.put(persistenceUnitName, emf); } return emf; }
Above code needs some synchronization.