Different ways of getting the EntityManager
问题 The usual idiom I see for creating the EntityManager is something like this: public class BaseDao { private static final String PERSISTENCE_UNIT_NAME = "Employee"; EntityManagerFactory factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); public EntityManager getEntityManager() { return factory.createEntityManager(); } } Then it is used like this: Employee emp = new Employee(); emp.setName("Joe M"); getEntityManager().persist(emp); Question is why not do it this way: public