Search code examples
javaannotationsentitymanagerpersistence-unit

Will @PersistenceUnit close my EntityManagerFactory when application is destroyed?


If i use the following

@PersistenceUnit(unitName="mongo")
EntityManagerFactory emf;

EntityManager em = emf.createEntityManager();

Will this annotation make sure that the EntityManagerFactory closes gracefully when application is destroyed?


Solution

  • Yes an injected EntityManagerFactory is automatically closed by the container.