`

session

 
阅读更多

getCurrentSession

从上下文找,有,用旧的,没有,建新的
事物提交自动close
opensession
每次都是新的,必须关闭

 

//Session session = sessionFactory.opensession();

Session session = sessionFactory.getCurrentSession();

 

session.beginTransaction();

session.save();

 

Session session2 = sessionFactory.getCurrentSession();

System.out.println(session==session2);//true

 

session.getTransaction.commit();

 

Session session3 = sessionFactory.getCurrentSession();

System.out.println(session==session3);//false

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics