Java技术篇:HC映射专家分析(2)为了帮助考生系统的复习,全面的了解考试教材的相关重点,小编特搜集整理了同步训练习题,希望对您参加本次考试有所帮助!
Session session = sessionFactory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
// 创建主键变量
pid = (Integer) session.save(user);
tx.commit();
} catch (RuntimeException e) {
if (tx != null)
tx.rollback();
throw e;
} finally {
session.close();
}
// 关闭sessionFactory
sessionFactory.close();
}
}
运行结果:
控制台:
20:47:57,366 DEBUG SQL:346 - insert intossh.c_user (age, firstname, lastname, address, zipcode, tel) values (?, ?, ?,?, ?, ?)
更多关注:
