什么是hibernate中的上下文会话? [英] What is contextual sessions in hibernate?

查看:109
本文介绍了什么是hibernate中的上下文会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 什么是Hibernate中的上下文会话?

  2. 当我使用上下文会话实现接口创建和关闭会话时
  3. $ b $将Hibernate的 Contextual Session 想象成一个当前映射的映射。

    解决方案会话到用户的上下文。例如:单个事务可以是这样一个上下文,因此如果Hibernate Session的生命周期与该事务的生命周期相匹配,那么Session可以被称为上下文,其中单个事务定义了这样一个上下文。有时这个特定的案例被标记为 session-per-request 模型。



    一个Hibernate接口 CurrentSessionContext 可以映射当前会话(例如 SessionFactory.getCurrentSession())到不同的上下文。这个接口有3个实现:


    • JTASessionContext :当前会话由JTA事务进行跟踪和作用域。这里的处理过程与之前的仅适用于JTA的方法完全相同。详情请参阅Javadocs。

    • ThreadLocalSessionContext :当前会话由执行线程跟踪。详情请参阅Javadocs。

    • ManagedSessionContext :当前会话由执行线程跟踪。但是,您有责任使用此类上的静态方法绑定和取消绑定Session实例:它不会打开,刷新或关闭会话




    查看 Architecture Architecture Session 是Hibernate文档的一部分,以获得更多官方的详细信息。


    1. What is contextual session in Hibernate?
    2. When I created and closed a sessions in between use contextual session implementation interfaces?

    解决方案

    Think of Hibernate's Contextual Session as a mapping of a current Session to a user's Context.

    For example: a single transaction could be such a context, hence if the Hibernate Session's lifecycle matches a life of this transaction, the Session could be called contextual, where a single transaction defines such a context. Sometimes this particular case is labeled as a session-per-request model.

    A Hibernate interface CurrentSessionContext is there to map a current session ( e.g. SessionFactory.getCurrentSession() ) to different contexts. This interface has 3 implementations:

    • JTASessionContext: current sessions are tracked and scoped by a JTA transaction. The processing here is exactly the same as in the older JTA-only approach. See the Javadocs for details.

    • ThreadLocalSessionContext: current sessions are tracked by thread of execution. See the Javadocs for details.

    • ManagedSessionContext: current sessions are tracked by thread of execution. However, you are responsible to bind and unbind a Session instance with static methods on this class: it does not open, flush, or close a Session

    Take a look at the Architecture Current Session part of the Hibernate documentation for more "official" details.

    这篇关于什么是hibernate中的上下文会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆