java.lang.Object | |
↳ | org.hibernate.context.ThreadLocalSessionContext |
A CurrentSessionContext
impl which scopes the notion of current
session by the current thread of execution. Unlike the JTA counterpart,
threads do not give us a nice hook to perform any type of cleanup making
it questionable for this impl to actually generate Session instances. In
the interest of usability, it was decided to have this default impl
actually generate a session upon first request and then clean it up
after the Transaction
associated with that session
is committed/rolled-back. In order for ensuring that happens, the sessions
generated here are unusable until after beginTransaction()
has been called. If close() is called on a session managed by
this class, it will be automatically unbound.
bind(Session)
and unbind(SessionFactory)
methods are
provided to allow application code to explicitly control opening and
closing of these sessions. This, with some from of interception,
is the preferred approach. It also allows easy framework integration
and one possible approach for implementing long-sessions.
The buildOrObtainSession()
, isAutoCloseEnabled()
,
isAutoFlushEnabled()
, getConnectionReleaseMode()
, and
buildCleanupSynch()
methods are all provided to allow easy
subclassing (for long-running session scenarios, for example).
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
ThreadLocalSessionContext.CleanupSynch | JTA transaction synch used for cleanup of the internal session map. |
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
factory |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Associates the given session with the current thread of execution.
| |||||||||||
Retrieve the current session according to the scoping defined
by this implementation.
| |||||||||||
Unassociate a previously bound session from the current thread of execution.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Strictly provided for subclassing purposes; specifically to allow long-session
support.
| |||||||||||
Mainly for subclass usage.
| |||||||||||
Getter for property 'factory'.
| |||||||||||
Mainly for subclass usage.
| |||||||||||
Mainly for subclass usage.
| |||||||||||
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
org.hibernate.context.CurrentSessionContext
|
Associates the given session with the current thread of execution.
session | The session to bind. |
---|
Retrieve the current session according to the scoping defined by this implementation.
HibernateException |
---|
Unassociate a previously bound session from the current thread of execution.
Strictly provided for subclassing purposes; specifically to allow long-session support.
This implementation always just opens a new session.Mainly for subclass usage. This impl always returns after_transaction.
Getter for property 'factory'.
Mainly for subclass usage. This impl always returns true.
Mainly for subclass usage. This impl always returns true.