`
QIAN_QIAN
  • 浏览: 136816 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

getCurrentSession()与openSession()

阅读更多

1、getCurrentSession()与openSession()的区别?
 * 采用getCurrentSession()创建的session会绑定到当前线程中,而采用openSession()
   创建的session则不会
 * 采用getCurrentSession()创建的session在commit或rollback时会自动关闭,而采用openSession()
   创建的session必须手动关闭
  
2、使用getCurrentSession()需要在hibernate.cfg.xml文件中加入如下配置:
 * 如果使用的是本地事务(jdbc事务)
 <property name="hibernate.current_session_context_class">thread</property>
 * 如果使用的是全局事务(jta事务)
 <property name="hibernate.current_session_context_class">jta</property>

分享到:
评论

相关推荐

    SessionFactory.getCurrentSession与openSession的区别

    博文链接:https://shaqiang32.iteye.com/blog/201918

    getCurrentSession 与 openSession() 的区别

    NULL 博文链接:https://bbxyhaihua.iteye.com/blog/505085

    ssh中getCurrentSession的使用

    ssh整合中getCurrentSession()的使用,个人写的练习,备忘用,不建议下载

    新Hibernate SessionFactory().getCurrentSession()猫腻

    NULL 博文链接:https://zgdkik.iteye.com/blog/1835667

    hibernate 学习笔记

    hibernate 学习笔记: 了解hibernate的基本概念 配置hbm.xml cfg.xml 快速入门案例3: 从domain-xml-数据库表 ...openSession()和getCurrentSession() 线程局部变量模式 transaction事务 在web项目中开发hibernate

    java 调用存储过程列子

    学生在学习jdbc的时候,会问到怎么调用存储过程,现在将java调用oracle存储过程的示例总结如下

    OA项目SSH整合框架

    Assert.assertNotNull(sessionFactory.openSession()); } 2,配置声明式事务(使用基于注解的方式) 1,配置 &lt;!-- 配置事务管理器 --&gt; &lt;property name="sessionFactory" ref="sessionFactory"&gt;...

    Java常见面试题208道.docx

    123.在 hibernate 中 getCurrentSession 和 openSession 的区别是什么? 124.hibernate 实体类必须要有无参构造函数吗?为什么? 十三、Mybatis 125.mybatis 中 #{}和 ${}的区别是什么? 126.mybatis 有几种分页方式...

    Java面试宝典2020修订版V1.0.1.doc

    9、openSession和getCurrentSession 90 10、拦截器的作用?拦截器和过滤器的区别? 91 11、struts.xml中result的type有哪些类型? 91 12、什么时候用JDBC什么时候用Hibernete; 91 13、hibernate 数据的三个状态 91 ...

    NHibernate Demo

    .GetCurrentSession();不带参数的情况下Web.config中一定要有hibernate-configuration节 5.连接是单线程的,在整个httpRequest处理过程中是公用的,缓存在HttpContext context中 see ref NHibernateHelper.getSession....

    无垠式代码生成器最新功能与文档增强版0.7.22

    3)增强修复S2SH技术栈,不再使用openSession语句,而是使用getSessionFactory().getCurrentSession(), Spring 3,Spring 4通用,同时web.xml里增加SpringOpenSessionInViewFilter ===============0.7.19.2==========...

    basic-common2h3:基于hibernate3的BaseDao,完成增删改查、分页操作

    通过getCurrentSession方法获取session操作对象。 示例: public interface IUserDao extends IBaseDao { } 3、定义UserDao并实现IUserDao接口,且要实现BaseDao类还需要传入泛型。 BaseDao完成了具体的CRUD的方法。...

    mysql+jdbc+jsp+Hibernate3.2+tomcattomcat5.028成功测试

    Session session1 =sessionFactory.getCurrentSession(); session1.beginTransaction(); &lt;br&gt; String title="jkh" ; Date theDate= new Date(); Event theEvent = new Event(); theEvent....

    对DAO编写单元测试[4]

    编写对DAO编写单元测试[4]publicabstractclassTransactionCallback{publicfinalObjectexecute()throwsException{Transactiontx=HibernateUtil.getCurrentSession().beginTransaction();try{Objectr=doInTransaction...

    三大框架下分页源代码

    Query query = getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery(sql); query.setFirstResult(pageno); query.setMaxResults(3); //设置每页显示的条数 List result = ...

    Hibernate 修改数据的实例详解

    Session currentSession = H3Utils.getCurrentSession(); currentSession.beginTransaction(); //创建 HQL String hqlString = update Person p set p.name=? , p.age=? where p.id=?; //构建 Query Query ...

Global site tag (gtag.js) - Google Analytics