First of all, thanks for answering.
I just would like to say that I'm not trying to invent anything, I'm just trying to solve a problem that I think is really frequent, but due to my skills on hibernate, I don't know how to solve.
The main problem I found on using he open-session-in-view pattern is that all the http requests share the same session, I mean one session per thread. This is manage by the session factory class.
The Filter executes the three following sentences:
Code:
1: sf.getCurrentSession().beginTransaction();
// Call the next filter (continue request processing)
2: chain.doFilter(request, response);
// Commit and cleanup
log.debug("Committing the database transaction");
3: sf.getCurrentSession().getTransaction().commit();
If you take a look at this code, it is very easy to have two or three http calls before line 2 finish for the first http call. If this happens, you are trying to open as much transactions as the http calls you have. Which produces an exception. This is from where my exception comes from.
What msj4u is doing is a bit different (which is an smart approach), open a new session each time you get a new connection, however, this will decrease the performance of the web applications.
Your two approaches will fulfill my requirements, open a session for each http request. I'll take the idea.
Thanks.