title: where we need to set hibernate session to thread local object
body: <pre><code>ThreadLocal&lt;Session&gt; tl = new ThreadLocal&lt;Session&gt;();
      tl.set(session);
  </code></pre>
  
  <p>to get the session,</p>
  
  <pre><code>  Employee emp = (Employee)((Session)tl.get().get(Employee.class, 1));
  </code></pre>
  
  <p>If our application is web based, the web container creates a separate thread for each request.
  If all these requests concurrently using the same single Session object , we should get 
  unwanted results in our database operations.
  To overcome from above results, it is good practice to set our session to threadLocal object
  which does not allows concurrent usage of session.I think, If it is correct the application performance should be very poor.
  What is the good approach  in above scenarios.
  If I'm in wrong track , in which situations we need to go for ThreadLocal.
  I'm new to hibernate, please excuse me if this type questioning is silly.
  thanks in advance.</p>