Solution to the exception in SSH lazy loading; solution to ssh Loading
Web. xml configuration file
<! -- Configure the Spring filter to solve the problem of lazy loading --> <filter-name> OpenSessionInViewFilter </filter-name> <filter-class> org. springframework. orm. hibernate3.support. openSessionInViewFilter </filter-class> </filter> <filter-mapping> <filter-name> OpenSessionInViewFilter </filter-name> <url-pattern> *. action </url-pattern> </filter-mapping> <! -- Configure the master filter of Struts2 --> <filter-name> struts2 </filter-name> <filter-class> org. apache. struts2.dispatcher. ng. filter. strutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name> struts2 </filter-name> <url-pattern>/* </url-pattern> </filter-mapping>
Note: It must be configured on the struts filter; otherwise, it will not work.
The OpenSessionInView mode may cause memory and database connection problems.
Because the OpenSessionInView mode is used, the Session lifecycle becomes longer. Although the Lazy Load problem is solved, the problem is that the first-level cache of Hibernate, that is, the lifecycle of the Session-level cache will become very long, if you perform a large volume of data operations on the Service layer, the data will actually be kept in the cache, which is very memory-consuming. There is also a database Connection problem because the Connection of the database is bound with the Session, so the Connection will not be released in time. Therefore, when the system is busy and the computing workload is very large, the number of connections in the data connection pool is insufficient.