Lazy loading exception: org.hibernate.LazyInitializationException: could not initialize proxy - no

sponsored links
Hibernate's Lazy initialization 1: n relationship, must be guaranteed to be in the same Session set for internal use this relationship, or Hiernate will throw an exception.

Two processing methods:
First, it is delay loaded questions to all pojo class linked, in the hibernate.cfg.xml file. Generally many-to-one in, set the tag in the set lazy = "false".

Second, with OpenSessionInViewFilter filter, attention hibernateFilter filters and filter struts2 mapping the order. To configure the transaction processing at the same time, otherwise it will result in session in read-only state do not modify, delete action.
That is configured in the web.xml file as follows:
<! - Spring ApplicationContext loaded configuration file directory. ->
<param-name> contextConfigLocation </ param-name>
<param-value> classpath *: spring / applicationContext.xml </ param-value>
</ Context-param>

<! - Lazy problem solving ->
<filter-name> hibernateFilter </ filter-name>
</ Filter-class>
</ Filter>

<! - Inherited Struts2 of FilterDispatcher class, with GBK encoding setting features such as the action with the struts2 filter function. ->
<filter-name> struts2 </ filter-name>
<filter-class> com.iman.nrms.opm.web.common.FilterDispatcher
</ Filter-class>
<param-name> encoding </ param-name>
<param-value> GBK </ param-value>
</ Init-param>
</ Filter>
<filter-name> struts-cleanup </ filter-name>
<filter-class> org.apache.struts2.dispatcher.ActionContextCleanUp
</ Filter-class>
</ Filter>
<filter-name> hibernateFilter </ filter-name>
<url-pattern> / * </ url-pattern>
</ Filter-mapping>
<filter-name> struts2 </ filter-name>
<url-pattern> / * </ url-pattern>
</ Filter-mapping>
<filter-name> struts-cleanup </ filter-name>
<url-pattern> / * </ url-pattern>
</ Filter-mapping>

Hibernate allows related objects, attributes lazy, lazy, but must ensure that the operation be limited to the same Hibernate Session within range. If the Service Layer Fanhui a delay load feature enabled De Ling Yu object To the Web, Ceng, Dang Web tier Fangwen to Naxie need lazy data, the The loading area of the object in the Hibernate Session Already closure, delay in loading data Daozhi access anomalies. The Spring has provided us with the OpenSessionInViewFilter filters for our well solved the problem. OpenSessionInViewFilter main function is to process each request to bind a Hibernate Session, even if the initial transaction has been completed, you can also load the Web layer delayed the operation. OpenSessionInViewFilter filter Hibernate Session bound to the request thread, it will automatically be Spring's transaction manager to detect. So OpenSessionInViewFilter apply to the use HibernateTransactionManager or JtaTransactionManager Service layer for transaction management environment, can also be used for non-transaction data read-only operation.
request -> open session -> open the connection, begin transaction -> lasting operation -> render (close connection, session) -> response omitted some of the process is not very concerned about.

This article comes from CSDN blog, reproduced, please indicate the source:
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Lazy loading exception: org.hibernate.LazyInitializationException: could not initialize proxy - no

  • Build flex + spring + blazeds + hibernate application

    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

    Hibernate connection pool configuration <! - Jdbc -> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </ property> <property name="connection.url"> jdbc: oracle: thin: @

  • hibernate generic generic DAO

    package org.lzpeng.dao; import; 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 *

  • Spring2.0 + hibernate3.1 + log4j + mysql demo

    applicationContext.xml Non-attachment jar package, necessary friends can send an email to todd.liangt @

  • Struts2 + hibernate + spring problem user log in

    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 secondary cache

    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's lazy strategy

    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 ...

  • spring struts2.0 hibernate bug killer 1

    exception There is no Action mapped for namespace / and action name checkLogin. - [Unknown location] com.opensymphony.xwork2.DefaultActionProxy.prepare ( 186) org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy ...

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries