• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question regarding servlet filter for implementing the OSIV pattern...

 
Ann Basso
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am looking at the filter given on Pg 737 of Manning's JPWH and I observed that it in the doFilter() method, the transaction is committed/rollbacked but the hibernate session is not closed at the end of the method.

Shouldn't there be a called to sf.getCurrentSession().close() in a finally block? Has it been left on purpose (i.e. is not needed) or is just an oversight?

thank you!
 
Ann Basso
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The text that follows the above code reads:

This filter acts as an interceptor for servlet requests. It runs every time a request hits the server and must be processed. It needs the SessionFactory on startup, and it gets it from the HibernateUtil helper class. When the request arrives, you start a database transaction and open a new persistence context. After the controller has executed and the view has been rendered, you commit the database transaction. Thanks to Hibernate’s auomatic Session binding and propagation, this is also automatically the scope of the persistence context.


And what about the hibernate session? What do I do with it??? Close it, right?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic