首页 > 代码库 > session详解
session详解
获的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详解
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。