Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • 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?
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!