Problems with the lazy policy of Hibernate

Source: Internet
Author: User
Transferred from: bytes. This problem often occurs in the early stages of the application, that is, the error message of session is closed. In fact, it is very simple. hibernate's connection to the database is maintained by its session. ProgramWhen the session is closed and then instantiated, the preceding error occurs. Therefore, you need to create a new seesion to complete the operation. (Why not set lazy load to false? What about hibernate? When more than a dozen tables are associated, the database is exhausted.) For me who have been using spring to integrate hibernate, these tasks do not need to be done by myself. First, I never operate hibernate on my own, all through spring's hibernatetemplate. Second, spring's strength is simple AOP. Naturally, it employees like me will not work on this. In spring Orm, three classes are provided for hibernate to handle the lazy load problem: hibernateinterceptor: handling issues at the business logic layer (common applications ), use proxyfactorybean to configure the bean in the actual business and inject the hibernateinterceptor into its interceptornames attribute. Then, your program does not have to worry about session issues. Spring will help you establish a session when necessary, if this parameter is not required, spring will disable it. Opensessioninviewinterceptor: Used in springmvc. If the interceptors attribute is injected into simpleurlhandlermapping, it is okay to access the object in the view (JSP, etc. Opensessioninviewfilter: Do not use springmvc. configure a filter in Web. xml so that other MVC frameworks will not be affected.

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.