在 SessionFactory 启动的时候, Hibernate 会根据配置创建相应的 CurrentSessionContext ,在getCurrentSession() 被调用的时候,实际被执行的方法是 CurrentSessionContext.currentSession() 。在currentSession() 执行时,如果当前 Session 为空, currentSession 会调用 SessionFactory 的 openSession 。所以 getCurrentSession() 对于 Java EE 来说是更好的获取 Session 的方法。

openSession() 与 getCurrentSession() 有何不同和关联呢?的更多相关文章

  1. Hibernate中openSession() 与 getCurrentSession()的区别

    1 getCurrentSession创建的session会和绑定到当前线程,而openSession每次创建新的session. 2 getCurrentSession创建的线程会在事务回滚或事物提 ...

  2. hibernate中openSession()跟getCurrentSession()方法之间的区别

    Hibernate openSession() 和 getCurrentSession的区别 getHiberanteTemplate .getCurrentSession和OpenSession 采 ...

  3. hibernate3.6-联合主键注解以及openSession和getCurrentSession区别

    [联合主键]>>>>配置方式:xml:    1. Student中单独创建StudentPk主键实体类 2. 配置: <composite-id name=" ...

  4. openSession和getCurrentSession的比较

    在比较openSession和getCurrentSession这两个方法之前,我们先认识一下这两个方法. 在进行配置信息管理时,我们一般进行一下简单步骤: Configuration cfg = n ...

  5. sessionFactory中的openSession和getCurrentSession的一些注意事项

    今天进行Hibernate测试时遇到了一个问题 我在用sessionFactory生产seesion时出现了故障,使用getCurrentsesstion时产生异常: Exception in thr ...

  6. Hibernate之openSession与getCurrentSession的区别

    openSession 与 getCurrentSession的区别(1)openSession 每一次获得的是一个全新的session对象,而getCurrentSession获得的是与当前线程绑定 ...

  7. HIbernate中openSession和getCurrentSession

      这两者的差别网上非常多资源,我这里就copy一下了,然后有点问题的是今天遇到的问题.   openSession和getCurrentSession的根本差别在于有没有绑定当前线程,所以,用法有差 ...

  8. Hibernate关于openSession和getCurrentSession的理解

    来源(转载):http://blog.csdn.net/woshisap/article/details/7024482 1:getCurrentSession会把Session和当前的线程关联起来, ...

  9. openSession()与getCurrentSession()的区别

    getCurrentSession创建的session会和绑定到当前线程,而openSession不会. getCurrentSession创建的线程会在事务回滚或事物提交后自动关闭,而openSes ...

随机推荐

  1. 【动态规划】【斜率优化】CDOJ1689 分序列

    斜率优化裸题,模型可以看http://www.cnblogs.com/ka200812/archive/2012/08/03/2621345.html #include<cstdio> # ...

  2. 4425: [Nwerc2015]Assigning Workstations分配工作站

    4425: [Nwerc2015]Assigning Workstations分配工作站 Description Penelope is part of the admin team of the n ...

  3. TCP,UDP,IP总结

    一.传输层的主要功能是什么? 分割并重新组装上层提供的数据流,为数据流提供端到端的传输服务. 二.传输层如何区分不同应用程序的数据流? 因为,对应传输层而言,它只需要知道目标主机上的哪个服务程序来响应 ...

  4. Virtualbox+ubuntu设置共享文件夹

    转:http://www.juwends.com/tech/unix_series/virtualbox-ubuntu-sharefolder.html 1. 进入系统,安装增强功能,安装完关闭系统. ...

  5. python笔记13-多线程实战篇(tomorrow)

    安装 1.tomorrow安装,用pip可以直接安装 pip install tomorrow 单线程 1.以下案例是单线程时候跑的情况,在下载图片的时候很耗时. # coding:utf-8 fro ...

  6. linux如何修改登录用户密码

    root登录后,passwd root可以修改root帐号的密码 其他具有sudo权限的用户登录后,sudo passwd root可以修改根帐号的密码 sudo passwd admin可以修改ad ...

  7. jQuery中,子页面与父页面之间的调用方法

    在jQuery中, 子页面查找父页面的元素 parent.$("#元素Id") 父页面调用子页面的元素 $("#子页面iframe的Id").contents( ...

  8. 一步一步学RenderMonkey(5)--渲染到纹理(RTT) 【转】

    转载请注明出处:  http://blog.csdn.net/tianhai110 渲染到纹理: 新建一个空effect; 添加渲染目标纹理, Add Texture-> Add Render ...

  9. springmvc实现简单的拦截器

    SpringMVC 中的Interceptor 拦截请求是通过HandlerInterceptor 来实现的.在SpringMVC 中定义一个Interceptor 非常简单,主要有两种方式,第一种方 ...

  10. 【笔记】js原生方法 在元素外部或内部实现添加元素功能(类似jq 的 insert 和 append)

    介绍的这个方法是:insetAdjacentHTML() 方法 此方法接收两个参数: 第一个参数必为下列值: beforebegin:在调用的元素外部的前面添加一个目标元素 afterend:在调用元 ...