在hibernate中更新记录时是否必须编写session.update(emploee)

时间:2016-09-20 05:39:43

标签: java hibernate

在hibernate中更新记录时是否必须编写session.update(employee)

这是我的代码。

public void updateEmployee() {

    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction transaction = null;
    try {
        transaction = session.beginTransaction();
        Employee employee = (Employee)session.get(Employee.class, 113);
        employee.setName("Prakash1");
        employee.setSal(60008);
        //session.update(employee);
        transaction.commit();
        System.out.println("Employee records updated!");
    } catch (HibernateException e) {

        transaction.rollback();

        e.printStackTrace();

    } finally {

        session.close();

    }
}

0 个答案:

没有答案