About S2SH Framework notes and solutions for hibernate lazy loading issues

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.