Class JTASessionContext
- java.lang.Object
-
- org.hibernate.context.spi.AbstractCurrentSessionContext
-
- org.hibernate.context.internal.JTASessionContext
-
- All Implemented Interfaces:
Serializable
,CurrentSessionContext
public class JTASessionContext extends AbstractCurrentSessionContext
An implementation ofCurrentSessionContext
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 timecurrentSession()
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()
, andgetConnectionHandlingMode()
methods; these are provided (along with thebuildOrObtainSession()
method) for easier subclassing for custom JTA-based session tracking logic (like maybe long-session semantics).- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
JTASessionContext.CleanupSync
JTA transaction sync used for cleanup of the internal session map.
-
Constructor Summary
Constructors Constructor Description JTASessionContext(SessionFactoryImplementor factory)
Constructs a JTASessionContext
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 PhysicalConnectionHandlingMode
getConnectionHandlingMode()
Mainly for subclass usage.protected boolean
isAutoCloseEnabled()
Mainly for subclass usage.protected boolean
isAutoFlushEnabled()
Mainly for subclass usage.-
Methods inherited from class org.hibernate.context.spi.AbstractCurrentSessionContext
baseSessionBuilder, factory, validateExistingSession
-
-
-
-
Constructor Detail
-
JTASessionContext
public JTASessionContext(SessionFactoryImplementor factory)
Constructs a JTASessionContext- Parameters:
factory
- The factory this context will service
-
-
Method Detail
-
currentSession
public Session currentSession() throws HibernateException
Description copied from interface:CurrentSessionContext
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.
-
buildOrObtainSession
protected Session buildOrObtainSession()
Strictly provided for subclassing purposes; specifically to allow long-session support. This implementation always just opens a new session.- Returns:
- the built or (re)obtained session.
-
isAutoCloseEnabled
protected boolean isAutoCloseEnabled()
Mainly for subclass usage. This impl always returns true.- Returns:
- Whether the session should be closed by transaction completion.
-
isAutoFlushEnabled
protected boolean isAutoFlushEnabled()
Mainly for subclass usage. This impl always returns true.- Returns:
- Whether the session should be flushed prior transaction completion.
-
getConnectionHandlingMode
protected PhysicalConnectionHandlingMode getConnectionHandlingMode()
Mainly for subclass usage. This impl always returns after_statement.- Returns:
- The connection release mode for any built sessions.
-
-