81,091
社区成员
发帖
与我相关
我的任务
分享
public void testSave1() {
Session session = null;
Transaction tx = null;
try {
session = HibernateUtils.getSession();
tx = session.beginTransaction();
。。。。。。。
session.save(user);
tx.commit();
}catch(Exception e) {
e.printStackTrace();
tx.rollback();
}finally {
HibernateUtils.closeSession(session);
}
}
public void save(User transientInstance) {
log.debug("saving User instance");
try {
getSession().save(transientInstance);
System.out.println("save user successful!");
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}