title: Spring-Hibernate used in a webapp,what are strategies for Thread safe session management
body: <p>I'm developing a web app with Spring and Hibernate and I was so obsessed by making he application thread safe and being able to support heavy load that based on my boss recommendation I end up writing my own <code>session</code> and a <code>session container</code> to implement a <code>session per request pattern</code>. Plus I have a lot of <code>DAOs</code> and me not willing to write the same <code>save method</code> for all the <code>DAOs</code> I copy paste this <a href="http://community.jboss.org/wiki/GenericDataAccessObjects" rel="nofollow noreferrer">Hibernate <code>GenericDAO</code></a> (I can't tell it's the same thing because at the time hibernate wasn't owned by jboss) and do the plumbing stuff, and under pressure, all become quickly complicated and on production, the is StaleObjectException and duplicated data right, and i have the feeling that it's time to review what I've done, simplify it and make it more robust for large data handling. One thing you should know is that one request involves many DAO's.</p>
  
  <p>There is quartz running for some updates in the database.</p>
  
  <p>As much as I want to tune everything for the better I lack time to do the necessary research plus Hibernate is kind of huge (learning).</p>
  
  <p>So this is it, I'll like to borrow your experience and ask for few question to know what direction to take.  </p>
  
  <p><strong>Question 1</strong> : is Hibernate generated uuid safe enough for threading environment and avoiding StaleObjectException?</p>
  
  <p><strong>Question 2</strong> what are best strategy to use hibernate getCurrentSession in threadSafe scenario (I've read about threadlocal stuff but didn't get too much understanding so didn't do it)  </p>
  
  <p><strong>Question 3</strong> : will HIbernateTemplate do for the simplest solution approach?  </p>
  
  <p><strong>Question 4</strong> : what will be your choice if you were to implement a connection pool and tuning requirement for production server?</p>
  
  <p>Please do no hesitate to point me to blogs or resources  online , all that I need is a approach that works for my scenario. your approach if you were to do this.</p>
  
  <p>Thanks for reading this, everybody's idea is welcomed...</p>