public List<User> add() { String persistenceUnitName = "SimplePU"; EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnitName); EntityManager em = emf.createEntityManager(); //em.getTransaction().begin(); //em.getReference(User.class, 1L); String jpql="select t from User t"; //em.close(); //emf.close(); return em.createQuery(jpql).getResultList();
我测试只有不关闭em和emf才能输出的jsp,用jpa的方式能不能查,其他的框架没学,就学了serlvet,spring,springmvc,serlvet上学期查过了,这次想用jpa的方式查询