代码:
private static void editInfo() {
Session session = null;
try {
session = HibernateUtil.getSession();
if (session != null) {
session.beginTransaction();
Person p = new Person("王三", 22, "男", "北京");
session.save(p);
session.delete(p);
p.setId(null);
session.save(p);
session.getTransaction().commit();
}
} catch (Exception ex) {
if (session != null) {
session.getTransaction().rollback();
}
ex.printStackTrace();
} finally {
HibernateUtil.CloseSession();
}
}
控制台显示:
Hibernate:
insert
into
PERSON
(NAME, AGE, GENDER, ADDRESS)
values
(?, ?, ?, ?)
Hibernate:
delete
from
PERSON
where
ID=?
Hibernate:
insert
into
PERSON
(NAME, AGE, GENDER, ADDRESS)
values
(?, ?, ?, ?)
按照Hibernate的规定执行应该是insert,insert,delete,但不知道为什么这里是insert,delete,insert,请各位大哥指教一下。