Today, when I was learning Shiro, I built a springmvc+spring+hibernate integration framework, and then I made an error when I ran the one-many,many-one mapping relationship with lazy loading.
Could not initialize proxy-no the session and then went on the internet to find data, which means that since Hibernate and spring are integrated, the hibernate session is given to spring management and the request comes in to open SE Ssion, the session is closed when the request completes. When we want to use lazy load to get data, the original session is closed and no more data can be obtained. Thus, spring specifically makes a filter org.springframework.orm.hibernate4.support.OpenSessionInViewFilter for this situation. It can maintain the declaration cycle of the hibernate session between the opening and closing of the view. In this way, as long as our view is not closed, we can use Ajax to get the data through lazy loading.
The specific configuration is as follows:
<filter>
<filter-name>openSessionInView</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
This is the HIBERNATE4 configuration, to be configured in Web.xml and because XML loading is in a certain order, so try to write it up.
After the configuration is complete, you can use it happily.