Could not initialize Proxy-no Session

Source: Internet
Author: User

This is a fine question:
Because when we load an object out of hibernate, we use the proxy object, which means that when we execute the Load method, we do not send the SQL statement, but instead return a proxy object. Only when the specific use of the get** method will be issued SQL statements, will go to the database check. But when we open the session, close the session to the srping to do, when the load is finished, our session will be srping closed, if we in the JSP page or other places to use the Get method to take the value of the error will be reported.
workaround One: But if we use the Get method in hibernate to solve the problem of taking a single object , because the GET method sends SQL statements directly, the data we want from the database get out and put in memory.
If we take a single object can use the Get method is not a problem, but if we take the object has an associated object with get is problematic, because it does not take the associated object out, but if the page is used on the associated object will also report no session problem
Solution Two: Use the srping filter (to be added to the strutsfilter in front, because it also has a sequence, the principle of FIFO)
In our web. XML, add

<filter><filter-name>openSessionInView</filter-name><filter-class> org.springframework.orm.hibernate3.support.opensessioninviewfilter</filter-class></filter>< filter-mapping><filter-name>opensessioninview</filter-name><url-pattern>/*</ Url-pattern></filter-mapping>
This is to let Opensession closesession full to the View section, the last view part of the session and then to close the session will not have the above error

Could not initialize Proxy-no Session

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.