Personally I would think that if you close your thread local session in the ServiceManager and then have to reconnect it you've more or less defeated the purpose of storing an "open" session. If something were to go wrong and for some reason the session didn't get closed Hibernate would still detect it and clean up after you and issue a warning so the connections would not be left hanging indefinitely.
to
dmmorris:
Have you mapped the filter to run on more than just the ActionServlet?
I'm using Struts and I don't have to do any fancy checking of request extension. The filter runs and opens a session whenever a request is made to the Struts ActionServlet (i.e. every Struts request) and finishes and closes the session after the view has been rendered and control passes out of the ActionServlet. All of the jsp rendering et. al. is covered by this because the ActionServlet hasn't actually finished until the view is constructed.
pseudo:
Code:
- filter starts (opens session)
- ActionServlet starts
- view is rendered
- ActionServlet finishes
- filter finishes (closes session)
to
moedusa:
Quote:
...the quantity of simultaneosly rendered requests will be limited by connection pool capabilities...
That could very well be true but unless you get a very large volume of concurrent requests so close together that they can't finish executing fast enough to free up connections that wouldn't be a problem.
Quote:
...if ServiceManager will recieve sessions from ServletFilter, it (ServiceManager) should NOT close sessions, is that right?
That is correct, it should NOT close the sessions.
Quote:
in the case of using ServiceManager from outside web context at all, it should be provided with manually opened and closed session?
Also correct, that is why it is good to have your ServiceManager be passed an open session as a parameter rather than ask for one explicitly from somewhere (this way you can use the filter to get a session when running in your web container and you can use another approach for your unit tests and still use the same ServiceManager etc. for both scenarios).