Hibernate中创建Session(会话)接口的方法

通过会话工厂sessionFactory创建session

openSession()和getCurrentSession()的区别

  1. 采用getCurrentSession()创建的session会绑定到当前线程中,而采用openSession()创建的线程则不会
  2. 采用getCurrentSession()创建的session在commit()或rollback()时会自动关闭,而采用openSession()创建的session必须手动关闭
posted @ 2018-01-30 12:55  ___struggle  阅读(783)  评论(0编辑  收藏  举报