Would this be correct?
public List<Foo> read() { EntityManagerFactory emf = Persistence.createEntityManagerFactory( getServletContext().getInitParameter("database")); EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder(); CriteriaQuery<Foo> criteriaQuery = criteriaBuilder.createQuery(Foo.class); Root<Foo> root = criteriaQuery.from(Foo.class); List<Foo> allFoo = (List<Foo>) criteriaQuery.select(root); em.getTransaction().commit(); em.close(); emf.close(); return allFoo; }