【发布时间】:2017-07-06 09:09:17
【问题描述】:
我是休眠新手。我想了解事务提交后的行为。考虑下面的代码-
Employee 类是将其对象插入/删除数据库的类。
public static void main(String[] args) {
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.getCurrentSession();
long id = 2;
try {
session.beginTransaction();
Employee employee = (Employee) session.get(Employee.class, id);
session.delete(employee);
session.getTransaction().commit();
employee.getName(); /*What will happen at this line*/
}
catch (HibernateException e) {
e.printStackTrace();
session.getTransaction().rollback();
}
}
【问题讨论】:
标签: java hibernate transactions entity commit