An implementation of {@link CurrentSessionContext} which scopes the notionof 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 {@link #currentSession()} is called, a new session will be opened and itwill be associated with that JTA transaction.
Note that the sessions returned from this method are automatically configured with both the {@link org.hibernate.cfg.Environment#FLUSH_BEFORE_COMPLETION auto-flush} and{@link org.hibernate.cfg.Environment#AUTO_CLOSE_SESSION auto-close} attributes set totrue, 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 {@link #isAutoFlushEnabled()}, {@link #isAutoCloseEnabled()}, and {@link #getConnectionReleaseMode()} methods; these are provided (along withthe {@link #buildOrObtainSession()} method) for easier subclassing for customJTA-based session tracking logic (like maybe long-session semantics).
@author Steve Ebersole