标签:cto hiberna where mit sele sel find manage 数据库
@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=?
*/
System.out.println(s); // Student{sid=1, sname=‘刘备‘, sage=23}
s.setSname("陈宫");
System.out.println(s); // Student{sid=1, sname=‘陈宫‘, sage=23}
em.refresh(s);
/*
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=?
*/
System.out.println(s); // Student{sid=1, sname=‘刘备‘, sage=23}
tx.commit();
em.close();
factory.close();
}
标签:cto hiberna where mit sele sel find manage 数据库
原文地址:https://www.cnblogs.com/wumingoo1/p/13399272.html