Package org.hibernate.context.spi
Interface CurrentSessionContext
-
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
AbstractCurrentSessionContext
,JTASessionContext
,ManagedSessionContext
,ThreadLocalSessionContext
public interface CurrentSessionContext extends Serializable
Defines the contract for objects which are able to manage the lifecycle of aSession
associated 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
SessionFactoryImplementor
, - be thread-safe,
- be fully serializable,
- guarantee that it
destroys
every 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".
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Session
currentSession()
Retrieve the current session according to the scoping defined by this implementation.
-
-
-
Method Detail
-
currentSession
Session currentSession() throws HibernateException
Retrieve the current session according to the scoping defined by this implementation.- Returns:
- The current session.
- Throws:
HibernateException
- Typically indicates an issue locating or creating the current session.
-
-