- sessionFactory.openSession和sessionFactory.getCurrentSession
openSession 会新建一个session,需要close
getCurrentSession在session没有提交之前(session.getTransaction().commit()),从上下文找,如果有,用旧的session,session一旦提交,拿的就是新的了。
1)用途,界定事务边界
2)事务提交,自动close
3)current-session_context_class(jta thread)(java transaction api)
a)thread使用connection
b)jta需要中间件支持(Tomcat不支持)