标签:style blog io color os sp on 数据 div
1 public void testMerge(){ 2 Session session = sessionFactory.openSession(); //生成一个新的session 3 session.beginTransaction(); //开启事物 4 5 Student stu = (Student) session.get(Student.class, Integer.valueOf(1)); 6 stu.setName("lisi"); 7 8 session.save(stu); 9 10 session.getTransaction().commit(); //提交事务 11 session.close(); //关闭session 12 13 Session session1 = sessionFactory.openSession(); //生成一个新的session 14 session1.beginTransaction(); //开启事物 15 Student stu1 = (Student) session1.get(Student.class, Integer.valueOf(1)); 16 stu.setName("lisi1"); 17 // session1.update(stu); //异常 18 session1.merge(stu); //成功执行 19 20 session1.getTransaction().commit(); //提交事务 21 session1.close(); //关闭session 22 }
标签:style blog io color os sp on 数据 div
原文地址:http://www.cnblogs.com/sidianshui/p/4128922.html