The project encountered in the ssh lazy loading problem (finally solved !!!)
Lazy loading (Load On Demand) is a unique and powerful data access method, which can automatically when the user scrolls the page to get more data, and the new data obtained will not affect the display of the original data, while minimize the consumption of server resources. (Baidu said)
Popular point is not looking to identify an object associated with the object of his, but need the associated objects (or properties) only to find the database, also known as lazy loading.
In general, we are in the many-to-one of many set lazy = false, which is available to our own hibernate.
Then lock up the spring session, we can put it another way: OpenSessionInViewFilter
OpenSessionInViewFilter is a Spring provided a support class for Hibernate
Generally, we can be so configured directly in the web.xml
<!-- Spring Provides avoidance of Hibernate lazy loading exception filters Let the Session after the completion of the request for interpretation and close , Thereby avoiding lazy load exception --> <filter> <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>/*</url-pattern> </filter-mapping>
This will save a lot of trouble to many places do not need to set up in each of the lazy = false
This method should be very popular, I also got from the Internet. Yet the novice I was directly used to take over the project are not deployed from the effects of N times, really depressing. Each error: org.hibernate.LazyInitializationException: could not initialize proxy - no Session.
Obviously, session closed. Tragedy
Collapse at the time, why the Internet are saying, but it is always wrong.
Know that today I saw this article http://www.javaeye.com/topic/32001
Suddenly the fog suddenly.
Since the spring tube from the sessionFactory, session must also be obtained through his fishes Yeah, so this part of the mapping of the mapping should also be placed on the back of struts2, after this class, and then do the real Action codes, and finally Hibernate Session according to the situation will be closed.
The following is the complete web.xml:
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- struts2 --> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <!-- spring Consolidation struts2 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:daoContext.xml,classpath:actionContext.xml,classpath:serviceContext.xml,classpath:applicationContext.xml</param-value> </context-param> <!-- Spring Provides avoidance of Hibernate lazy loading exception filters Let the Session after the completion of the request for interpretation and close , Thereby avoiding lazy load exception --> <filter> <filter-name>openSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter> <!-- The following 2 mapping Can you swap position --> <filter-mapping> <filter-name>openSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
ok, so lazy save in each of the many configurations.
Evidently not enough for understanding the underlying ah. To fuel it!
Related Posts of The project encountered in the ssh lazy loading problem (finally solved !!!)
Database-driven update classes12-9i.jar Hibernate modify the configuration of the following code <bean/> <bean Lazy-init="true"> <property name="nativeJdbcExtractor"> <ref local="nativejdbcExtractor"/>
applicationContext.xml file content <? xml version = "1.0" encoding = "UTF-8"?> <beans xmlns = " http://www.springframework.org/schema/beans " xmlns: xsi = " http://www.w3.org/2001/XMLSchema-instance " ...
Build flex + spring + blazeds + hibernate application First, set up the project blazeds 1, will blazeds.war extract to a directory, such as: myflex /; 2, set up java works were such as: MyFlex, in the orientation of selection create project from exis ...
Hibernate connection pool configuration <! - Jdbc -> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </ property> <property name="connection.url"> jdbc: oracle: thin: @ 10.203.14.132:15
package org.lzpeng.dao; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *
applicationContext.xml Non-attachment jar package, necessary friends can send an email to todd.liangt @ gmail.com
dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q
Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml (the document code in hibernate package directory ...
hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...
1, object-oriented features of what has 1. Abstract: Abstract is that it has overlooked a subject has nothing to do with the current goal of those aspects in order to more fully with the current objectives of the attention-related aspects. Abstract does n