hibernate中: is not valid without active transaction

来源:互联网 发布:php object to json 编辑:程序博客网 时间:2024/06/07 09:06

Session session= sf.getCurrentSession();

Teacher t = (Teacher)session.get(Teacher.class,2);

System.out.println(t.getId());

Teacher t2 = (Teacher)session.load(Teacher.class, 1);

System.out.println(t2.getName());

session.getTransaction().commit();

会报错,把sf.openSession()就不报错了,openSession()每一次都产生一个新的session

原创粉丝点击