unixlibre wrote:
From Hibernate docs I've understood that, given the thread-bound session, the second call to getCurrentSession() should return the same session. The observed behaviour is wrong or do I have a problem in the hibernate config? Using the newly obtaned session will fall into the session-per-operation anti-pattern?
Im not sure where you saw the above, this is also from the hibernate docs
Quote:
A Session begins when it is first needed, when the first call to getCurrentSession() is made. It is then bound by Hibernate to the current thread. When the transaction ends, either through commit or rollback, Hibernate automatically unbinds the Session from the thread and closes it for you. If you call getCurrentSession() again, you get a new Session and can start a new unit of work. This thread-bound programming model is the most popular way of using Hibernate, as it allows flexible layering of your code (transaction demarcation code can be separated from data access code, we'll do this later in this tutorial).
I have not tried this, but can you set the auto_close_session value to be false, so that the session is not closed at the end of a commit/rollback? That way, you could have the session maintained as a session-per-request pattern, but its your responsibility to close it after the thread has completed?