public class JTASessionContext extends AbstractCurrentSessionContext
CurrentSessionContext
which scopes the notion
of a current session to a JTA transaction. Because JTA gives us a nice tie-in to clean up after
ourselves, this implementation will generate Sessions as needed provided a JTA transaction is in
effect. If a session is not already associated with the current JTA transaction at the time
currentSession()
is called, a new session will be opened and it will be associated with that
JTA transaction.
Note that the sessions returned from this method are automatically configured with both the
auto-flush
and
auto-close
attributes set to true, meaning
that the Session will be automatically flushed and closed as part of the lifecycle for the JTA
transaction to which it is associated. Additionally, it will also be configured to aggressively
release JDBC connections after each statement is executed. These settings are governed by the
isAutoFlushEnabled()
, isAutoCloseEnabled()
, and getConnectionReleaseMode()
methods; these are provided (along with the buildOrObtainSession()
method) for easier
subclassing for custom JTA-based session tracking logic (like maybe long-session semantics).Modifier and Type | Class and Description |
---|---|
protected static class |
JTASessionContext.CleanupSync
JTA transaction sync used for cleanup of the internal session map.
|
Constructor and Description |
---|
JTASessionContext(SessionFactoryImplementor factory)
Constructs a JTASessionContext
|
Modifier and Type | Method and Description |
---|---|
protected Session |
buildOrObtainSession()
Strictly provided for subclassing purposes; specifically to allow long-session
support.
|
Session |
currentSession()
Retrieve the current session according to the scoping defined
by this implementation.
|
protected ConnectionReleaseMode |
getConnectionReleaseMode()
Mainly for subclass usage.
|
protected boolean |
isAutoCloseEnabled()
Mainly for subclass usage.
|
protected boolean |
isAutoFlushEnabled()
Mainly for subclass usage.
|
baseSessionBuilder, factory, validateExistingSession
public JTASessionContext(SessionFactoryImplementor factory)
factory
- The factory this context will servicepublic Session currentSession() throws HibernateException
CurrentSessionContext
HibernateException
- Typically indicates an issue
locating or creating the current session.protected Session buildOrObtainSession()
protected boolean isAutoCloseEnabled()
protected boolean isAutoFlushEnabled()
protected ConnectionReleaseMode getConnectionReleaseMode()
Copyright © 2019 JBoss by Red Hat. All rights reserved.