The so-called delay loading is lazy loading (lazy), delay loading.
When to use lazy load, I can only answer to use lazy load when loaded with lazy.
As for why lazy to load, that is, when we want to access the amount of data is too large, obviously with the cache is not appropriate, because the memory capacity is limited, in order to reduce concurrent volume, reduce the consumption of system resources,
We let the data load when it was needed, and we used lazy loading. Lazy loading of the exception there are many kinds of, you are referring to the session has been closed the exception? Because that beginner is most likely to encounter the situation is when you load a one-to-many relationship on the end of the object, and then after the transaction place, such as the page, but also want to get multiple objects inside the other than the ID of the time, will run out of this exception.
For example, you have a Grade object that associates a lot of Student objects with lazy loading.
You get a Grade object in your service with a database query, which has a set<student> students collection, but you don't do any further work on the object (such as Intialize things like that let lazy loaded proxy objects really instantiate it.
And then when you get to the presentation of the page, you go through the students collection, and you try to display the Name property of each student on the page (this property is not StudentID) this time it throws the session closed exception
In the SSH framework:
Opensessioninviewfilter can be used directly
Configuring in Configuration Files
Copy Code code as follows:
<filter-name>opensession</filter-name>
<filter-class> Org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
<filter-mapping>
<filter-name>opensession</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
The above is the entire content of this article, I hope that the small partners can enjoy.