- All Superinterfaces:
- All Known Implementing Classes:
public interface CurrentSessionContext extends SerializableDefines the contract for objects which are able to manage the lifecycle of a
Sessionassociated with a well-defined "context" or "scope", providing the concrete implementation behind the notion of the current session.
The lifecycle of the context/scope is not specified by Hibernate, and varies depending on the nature of the program. The only hard restriction is that the scope must be single-threaded. On the other hand, since state tends to build up in the first-level cache of session, sessions should typically not be associated with long-lived scopes.
The most typical example of a scope with which a current session might be associated is the HTTP request context in a web application.
An implementation of this interface must:
- have a constructor accepting a single argument of type
- be thread-safe,
- be fully serializable,
- guarantee that it
destroysevery session it creates, and
- ensure that each session it creates is the exclusive property of a single thread, since sessions contain fragile mutable state and are never considered thread-safe.
Every session factory has exactly one instance of this interface.
An implementation may be selected by setting the configuration property "hibernate.current_session_context_class".