sessionFactory.openSession()和sessionFactory.getCurrentSession的区别

sessionFactory.openSession重新创建一个session

sessionFactory.getCurrentSession 获取当前上下文中的session。

 

session在Hibernate中是非线程安全的轻量级的对象,在使用过程中要随用随释放。不像transationManager是重量级的设计(transationManager要连接数据库的操作,很耗资源,故要保留到应用结束。)

posted on 2017-04-18 00:36  码农时刻  阅读(332)  评论(0编辑  收藏  举报