Restructured handling of EntityManagerFactory.