changed when to close entityManager