What are contextual sleep sessions?

  • What is a contextual session in Hibernate?
  • When did I create and close sessions between context context context sessions?
+5
source share
2 answers

Think of the Hibernate Contextual Session as mapping your current session to user context.

For example: one transaction can be such a context, therefore, if the life cycle of a Hibernate session matches the life of this transaction, a session can be called contextual when one transaction defines such a context . Sometimes this particular case is marked as a session-per-request model.

The Hibernate CurrentSessionContext interface is designed to map the current session (for example, SessionFactory.getCurrentSession() ) to various contexts. This interface has 3 implementations:

  • JTASessionContext : Current sessions are monitored and processed by a JTA transaction. The handling here is exactly the same as in the earlier JTA approach. See Javadocs for more details.

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

  • ManagedSessionContext : Current sessions are tracked by the thread of execution. However, it is your responsibility to bind and untie the session instance with static methods in this class: it does not open, hide, or close the session

Take a look at the “Current Session Architecture” in the Hibernate documentation for more “official” details.

+8
source

Another very good link explaining the concept of Hibernate context session

http://relation.to/2037.lace

+1
source

Source: https://habr.com/ru/post/957735/


All Articles