Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Spring and the fly likes Doubt on OpenSessionInViewFilter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Doubt on OpenSessionInViewFilter" Watch "Doubt on OpenSessionInViewFilter" New topic

Doubt on OpenSessionInViewFilter

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345


I have a question regarding this filter. Actually it keeps the underlying Hibernate / JPA session open upon each request to a web component. Now say I have a jsp page where I have a list of countries and I have an entity that has country and city as fields with the city field being lazily loaded. Now when I request for the page that has the country, I issue a hql to fetch my list of countries. Now where does this concept of lazy loading come into picture when I click on a country on the screen to fetch the list of cities in a country? All I have to do is to submit a new request, start a new transaction to fetch all the details. I mean is the filter functionality only per request or can it sustain beyond? As per the specification of JSP / Servlets, the filters are done once the response is sent back to the client. I'm just thinking if that session can go beyond?? I would like to have some interesting discussions on this point here.

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
David Newton

Joined: Sep 29, 2008
Posts: 12617

It's implemented in a standard servlet filter--so it's per-request.

Whether or not is a good idea to use an OSiV filter is a different topic--I'm not convinced the potential performance penalties are worth the risk, but if people are paying attention it may not be that bad.
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
What is the problem you want to solve?

SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Doubt on OpenSessionInViewFilter
Similar Threads
Why are getters called multiple times?
Populating dropdown menu based on another
creating an array
session time out cheching using filter
Values not poulating in the dropdown box.