@Test
public void test() {
EntityManagerFactory factory = Persistence.createEntityManagerFactory("myJpa");
EntityManager em = factory.createEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
Student s = em.find(Student.class, 1L);
/*
Hibernate:
select
student0_.sid as sid1_0_0_,
student0_.sage as sage2_0_0_,
student0_.sname as sname3_0_0_
from
Student student0_
where
student0_.sid=?
*/
s.setSage(s.getSage() + 1);
em.flush();
/*
Hibernate:
update
Student
set
sage=?,
sname=?
where
sid=?
*/
tx.commit();
em.close();
factory.close();
}
原文:https://www.cnblogs.com/wumingoo1/p/13399343.html