当前位置: 代码迷 >> Java Web开发 >> 求解:hibernate session.get(Class clazz,Serializable id)返回空值解决方案
  详细解决方案

求解:hibernate session.get(Class clazz,Serializable id)返回空值解决方案

热度:791   发布时间:2016-04-17 00:35:44.0
求解:hibernate session.get(Class clazz,Serializable id)返回空值
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();
}
  相关解决方案