First, let's take a look at the diagram below, explaining a request flow for a Web application!
Description of lazy Load exception:
Lazy loading is when we query an object, all of its properties are to be detected!
If lazy loading is turned on, the session is closed on the service layer, and if our view does not need his attributes, then there will be no lazy loading exception, if the need for attributes, this time the session is closed so there will be lazy loading exception, At this point we will consider whether we can put the session on the request and then close it.
Solve:
The answer, of course, is to use a filter, close the session after the request is over, and configure the following configuration on the Web. xml: (note before the Struts filter)
1 <!--configuring spring issues with Hibernate lazy loading -2 <Filter>3 <Filter-name>Opensessioninviewfilter</Filter-name>4 <Filter-class>Org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</Filter-class>5 </Filter>6 <filter-mapping>7 <Filter-name>Opensessioninviewfilter</Filter-name>8 <Url-pattern>*.action</Url-pattern>9 </filter-mapping>
About S2SH Framework notes and solutions for hibernate lazy loading issues