A {@link org.hibernate.context.spi.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 session is committed/rolled-back. In order for ensuring that happens, the sessions generated here are unusable until after {@link Session#beginTransaction()} has beencalled. 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 are provided to allow applicationcode 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
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.