The Thread Local Session design pattern provides a way to bind each thread of execution with one Hibernate Session. This enables the Session to be propagated between different classes such as DAO (another common design pattern).
Say, for example, I have DAO1 and DAO2 used in the following code :
Code:
DAO1.doSomething();
DAO2.doSomethingElse();
Using the Thread Local Session, I can open and close a single Hibernate Session which will be bound to the runnnig thread, and my two DAOs will share the same Session, thus benefiting from advanced mechanism such as concurrency checks and cache. This would give something like :
Code:
ThreadLocalSession.openNewSession();
DAO1.doSomething(); // will use the session opened just above
DAO2.doSomethingElse(); // will use that same session
ThreadLocalSession.closeSession();
Laurent[/code]