7583354li
2015-11-24 17:19
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");
}
有什么区别?
Hibernate初探之单表映射
74810 学习 · 793 问题
相似问题
回答 1
回答 6