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