Restructured the handling of the EntityManagerFactory