A {@link CurrentSessionContext} impl which scopes the notion of currentsession 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 {@link org.hibernate.Transaction} associated with that sessionis committed/rolled-back. In order for ensuring that happens, the sessions generated here are unusable until after {@link Session#beginTransaction()}has been called. If
close() is called on a session managed by this class, it will be automatically unbound.
Additionally, the static {@link #bind} and {@link #unbind} methods areprovided 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 {@link #buildOrObtainSession}, {@link #isAutoCloseEnabled}, {@link #isAutoFlushEnabled}, {@link #getConnectionReleaseMode}, and {@link #buildCleanupSynch} methods are all provided to allow easysubclassing (for long-running session scenarios, for example).
@author Steve Ebersole