org.hibernate.context.spi.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 is opened and is associated with the JTA
transaction.
Note that the sessions returned from this method are automatically configured with both the
properties hibernate.transaction.flush_before_completion and
hibernate.transaction.auto_close_session set to true,
meaning that the session will be automatically flushed and closed as part of the lifecycle of the
JTA transaction with which it is associated. Additionally, it will be configured to aggressively
release JDBC connections after each statement is executed. These settings are governed by the
isAutoFlushEnabled(), isAutoCloseEnabled(), and getConnectionHandlingMode()
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. |
| Modifier and Type | Field and Description |
|---|---|
| private final transient Map | |
| private static final CoreMessageLogger |
| Access | Constructor and Description |
|---|---|
| public | JTASessionContext(SessionFactoryImplementor
The factory this context will service factory)
Deprecated
as a consequence of
Constructs a JTASessionContext
SessionFactoryImplementor being deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
| private JTASessionContext. | Returns: The cleanup synch.The transaction identifier under which the current session is registered. transactionIdentifier)Builds a |
| protected Session | Returns: the built or (re)obtained session.Strictly provided for subclassing purposes; specifically to allow long-session support. |
| public Session | currentSession()
Implements org. |
| protected PhysicalConnectionHandlingMode | Returns: The connection release mode for any built sessions.Mainly for subclass usage. |
| protected boolean | Returns: Whether the session should be closed by transaction completion.Mainly for subclass usage. |
| protected boolean | Returns: Whether the session should be flushed prior transaction completion.Mainly for subclass usage. |
| currentSessionMap | back to summary |
|---|---|
| private final transient Map<Object, Session> currentSessionMap | |
| LOG | back to summary |
|---|---|
| private static final CoreMessageLogger LOG | |
| JTASessionContext | back to summary |
|---|---|
| public JTASessionContext(SessionFactoryImplementor factory)
Deprecated as a consequence of Constructs a JTASessionContext
| |
| buildCleanupSynch | back to summary |
|---|---|
| private JTASessionContext. Builds a
| |
| buildOrObtainSession | back to summary |
|---|---|
| protected Session buildOrObtainSession() Strictly provided for subclassing purposes; specifically to allow long-session support. This implementation always just opens a new session.
| |
| currentSession | back to summary |
|---|---|
| public Session currentSession() throws HibernateException Implements org. Doc from org. Retrieve the current session according to the scoping defined by this implementation.
| |
| getConnectionHandlingMode | back to summary |
|---|---|
| protected PhysicalConnectionHandlingMode getConnectionHandlingMode() Mainly for subclass usage. This impl always returns after_statement.
| |
| isAutoCloseEnabled | back to summary |
|---|---|
| protected boolean isAutoCloseEnabled() Mainly for subclass usage. This impl always returns true.
| |
| isAutoFlushEnabled | back to summary |
|---|---|
| protected boolean isAutoFlushEnabled() Mainly for subclass usage. This impl always returns true.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final JTASessionContext | |
| private final Object |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | afterCompletion(int
The status of the transaction completion. i)Implements jakarta. |
| public void | beforeCompletion()
Implements jakarta. |
| context | back to summary |
|---|---|
| private final JTASessionContext context | |
| transactionIdentifier | back to summary |
|---|---|
| private final Object transactionIdentifier | |
| CleanupSync | back to summary |
|---|---|
| public CleanupSync(Object transactionIdentifier, JTASessionContext context) | |
| afterCompletion | back to summary |
|---|---|
| public void afterCompletion(int i) Implements jakarta. Doc from jakarta. This method is called by the transaction manager after the transaction is committed or rolled back.
| |
| beforeCompletion | back to summary |
|---|---|
| public void beforeCompletion() Implements jakarta. Doc from jakarta. The beforeCompletion method is called by the transaction manager prior to the start of the two-phase transaction commit process. This call is executed with the transaction context of the transaction that is being committed.
| |