public static void testUpdate1() {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
Teacher t = (Teacher)session.get(Teacher.class, 1);
System.out.println(t);//t返回为空;为什么》???
session.getTransaction().commit();
t.setName("zhanglaoshi");
Session session2 = sessionFactory.getCurrentSession();
session2.beginTransaction();
session2.update(t);
session2.getTransaction().commit();
}
希望高手指点,谢谢
------解决方案--------------------
public static void testUpdate1() {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
Teacher t = (Teacher)session.get(Teacher.class, 1);//谁知道 你的ID 有没有 1的
System.out.println(t);//t返回为空;为什么》???
session.getTransaction().commit();//查询用不着事务
t.setName("zhanglaoshi");
Session session2 = sessionFactory.getCurrentSession();
session2.beginTransaction();
session2.update(t);
session2.getTransaction().commit();
}