• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

about doFilter() method

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic