session=sessionFactory.getCurrentSession();Stundents stu=new Stundents(1, "老张", "男", new Date(), "武当山上");Stundents st=new Stundents(2, "l3l", "男", new Date(), "武当山上");session.save(stu);session.save(st);
session=sessionFactory.openSession();Stundents stu=new Stundents(1, "老张", "男", new Date(), "武当山上");Stundents st=new Stundents(2, "l3l", "男", new Date(), "武当山上");session.save(stu);session.save(st);
在事务提交后加一个 if(!session.isOpen()),就可以判断session是否会自动关闭
transaction.commit();
if(!session.isOpen())
{
System.out.println("getCurrentSession is close");
}
有什么区别?