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

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. ->
<context-param>
<param-name> contextConfigLocation </ param-name>
<param-value> classpath *: spring / applicationContext.xml </ param-value>
</ Context-param>

<! - Lazy problem solving ->
<filter>
<filter-name> hibernateFilter </ filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</ Filter-class>
</ Filter>

<! - Inherited Struts2 of FilterDispatcher class, with GBK encoding setting features such as the action with the struts2 filter function. ->
<filter>
<filter-name> struts2 </ filter-name>
<filter-class> com.iman.nrms.opm.web.common.FilterDispatcher
</ Filter-class>
<init-param>
<param-name> encoding </ param-name>
<param-value> GBK </ param-value>
</ Init-param>
</ Filter>
<filter>
<filter-name> struts-cleanup </ filter-name>
<filter-class> org.apache.struts2.dispatcher.ActionContextCleanUp
</ Filter-class>
</ Filter>
<filter-mapping>
<filter-name> hibernateFilter </ filter-name>
<url-pattern> / * </ url-pattern>
</ Filter-mapping>
<filter-mapping>
<filter-name> struts2 </ filter-name>
<url-pattern> / * </ url-pattern>
</ Filter-mapping>
<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: http://blog.csdn.net/maxracer/archive/2010/03/09/5358711.aspx

分类:Java 时间:2010-05-29 人气:586
分享到:
blog comments powered by Disqus

相关文章

  • DWR.xml configuration file specification 2009-05-24

    1, set up configuration files dwr.xml Dwr.xml any of the required documents are included in the statement DWR DOCTYPE line in the following format: <! DOCTYPE dwr PUBLIC "- / / GetAhead Limited / / DTD Direct Web Remoting 1.0 / / EN" "ht

  • SSH integration of the main configuration file reference 1 2010-12-28

    First is the web.xml configuration file: <? Xml version = "1.0" encoding = "GBK"?> <Web-app version = "2.5" xmlns = "http://java.sun.com/xml/ns/javaee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-in

  • Android initialization language (init. *. rc.init.conf file format) 2010-09-25

    Android initialization language (init. *. rc, init.conf file format) Android initialize language contains four types of statements: Actions (Action), Commands (commands), Services (services) and Options (option). All of these are units of behavior, a

  • Detailed Web.config configuration file 2010-12-03

    It took a little time to organize the basic ASP.NET Web.config configuration file to use. See it for beginners, as Web.config in the use of very flexible and can customize the number of nodes. So here only some of the more common nodes. <? Xml versio

  • dwr configuration file dwr.xml 2009-06-26

    I dwr Chinese document on a collation do dwr.xml purely jobs they take, there are useful do not forget to top friend you, leave a contact with the exchange of learning! Welcome to my site to exchange technical www.ithuzhu.com dwr.xml is the DWR confi

  • dwr configuration file dwr.xml Explained (change) 2010-04-12

    dwr.xml is the DWR configuration file. By default, it should put it in WEB-INF directory (web.xml directory) to create dwr.xml file dwr.xml file is structured as follows: <dwr> <! - Init is only needed if you are extending DWR -> <init>

  • svn + apache linux following the installation and configuration 2010-06-30

    Linux systems APACHE SVN server set up the whole process of a first related to the installation package is ready, I am here using the following several packages Apr: apr-1.2.11.tar.gz and apr-util-1.2.2.tar.gz Apache: httpd-2.2.6.tar.gz Subversion: s

  • ubuntu, apache configuration file 2010-08-30

    After installing Apache the most important thing is to know the Web document root where, for Ubuntu, the default is / var / www. How do you know it? apache2.conf where there is no DocumentRoot entry, httpd.conf is empty, so sure in other documents. A

  • CentOS 5.2, Linux 2.6 + kernel, Apache + MySQL + PHP installation and basic configuration process will be recorded & & apache installed as system services 2011-03-16

    Quote CentOS 5.2, Linux 2.6 + kernel, Apache + MySQL + PHP installation and basic configuration record & & the apache installed as system services collections environment: This article in the Linux operating system is CentOS 5.2, Linux 2.6 + kerne

  • spring is how to parse its own configuration file (1) 2010-03-29

    Recently all right, wanted to see how the spring loaded configuration file (for example: applicationContext.xml), fear that they will forget, so write it down: 1. Entrance org.springframework.web.context.ContextLoaderListener (where recommended liste

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 闽ICP备15018612号

processed in 0.101 (s). 12 q(s)