Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about doFilter() method

 
Nilesh Shekokar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

In my project there is a dofilter() method used in HibernateSessionFilter class. In too many classes the Hibernate currentSession() and beginTransaction() methods were called but session objects were not closed

As i know A filter is an object that performs filtering tasks on either the request to a resource (a servlet or static content), or on the response from a resource, or both.

The doFilter() also calls createSession() and closeSession()
So will it be necessary to close the session objects in those all classes or the filtering process will close the session automatically as it uses closeSession().

Please reply soon if anyone knows abt this....Thans in Advance
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes the filter closes all Sessions it opened (given the response is sent to the client). You need to use the tools that come with the filter so you use the Session that was opened by the filter. If you "just open" a Session by calling SessionFactory.openSession() then the filter does not know about it (the filter uses ThreadLocal to store the current Session and the tools will access this Session)

Take a look at the Springframework HibernateTemplate and TransactionProxy classes. They really simplify the Session/TX handling.

pascal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic