首页 > 其他 > 详细

session详解

时间:2016-10-03 00:02:37      阅读:349      评论:0      收藏:0      [点我收藏+]

获的session对象的方式:

  1.openSession

  2.getCurrentSession

如果使用getCurrentSession需要在hibernate.cfg.xml文件中进行配置:

  如果是本地事务(jdbc事务):<property name="hibernate.current_session_context_class">thread</property>

  如果是全局事务(jta事务):<property name="hibernate.current_session_context_class">jta</property>

 

openSession与getCurrentSession的区别

  1.getCurrentSession在事务提交或者回滚之后会自动关闭,而openSession需要手动关闭。如果使用openSession而没有手动关闭,多次之后会导致连接池溢出。(getCurrentSession每次获得session是一样的,openSession获得的是不同的)

  

session详解

原文:http://www.cnblogs.com/jasonlixuetao/p/5928380.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!