I've read the article here:
http://www.theserverside.com/tt/articles/article.tss?l=HibernateTomcat.
And it is said there:
Quote:
The difference between openSession() and getCurrentSession() is that the former, each time it is used, provides a brand new Hibernate Session. That is exactly what we want in our servlet. In contrast, getCurrentSession attempts to associate a Hibernate Session with a specific thread (the Singleton-per-Thread pattern), which Hibernate achieves via the use of an embedded (hidden) ThreadLocal. Unfortunately, Tomcat maintains a thread pool, and re-uses a given thread after a particular Http request is finished with it. Hence a brand new Http request can receive a previously used thread, which already happens to have a Hibernate Session associated with it (via the ThreadLocal), and getCurrentSession() may by chance receive an unrelated Hibernate Session when it ought to receive a brand new one. We may have a new Http session, and logically a new thread, but physically be re-using an existing thread. In this way, Tomcat 5.5.x and Hibernate 3.1 can confuse each other.
.
What do u think about it? Is that problem really exists?
Another problem is:
I'm keeping user profile in ThreadLocal, should i change the place? Will Session suit or maybe even here we have some problems?
I'm using hibernate 3.2.2 and tomcat 5.5.