Calling contains() after EntityManager.close() will throw an exception.

private static void persistEntity() {
EntityManager em = entityManagerFactory.createEntityManager();
Employee employee = new Employee("Joe", "IT");
em.getTransaction().begin();
em.persist(employee);
em.getTransaction().commit();
em.close();
System.out.println("After EntityManager.close(): " + em.contains(employee));
}
Original Post