因为有的时候我们使用JPA的时候由于某个实体的属性数据量比较大所以使用延迟加载来优化,而在struts2的action中使用到实体的时候却因为实体管理器已经关闭实体成为游离态,且数据延迟加载导致没有加载我们所需要的数据,比如:
@OneToMany(cascade = { CascadeType.REFRESH, CascadeType.REMOVE }, mappedBy = "parent")
public Set<ProductType> getChildTypes() {
return childTypes;
}
public void setChildTypes(Set<ProductType> childTypes) {
this.childTypes = childTypes;
}
这里使用到了延迟加载(默认方式),而实体管理器关闭之后我们在jsp中又要访问该数据:
${fn:length(type.childTypes)
这样会出现:failed to lazily initialize a collection of role
我们可以通过在配置文件中添加(必须要在FilterDispatcher之前):
<!-- 解决延迟加载时EntityManager已经关闭而无法使用的问题,但是性能损耗(要放在FilterDispatcher前面) -->
<filter>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<!-- include this if you use hibernate -->
<!--
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
-->
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
如此问题解决。
分享到:
相关推荐
* "git fetch" that grabs from a group of remotes learned to run the auto-gc only once at the very end. * A handful of Windows build patches have been upstreamed. * The code to read state files ...
2.6 Sorting a List of Objects by an Attribute of the Objects 2.7 Sorting by Item or by Attribute 2.8 Selecting Random Elements from a List Without Repetition 2.9 Performing Frequent Membership ...
npm install --save react-lazily-render 用法 () import React from 'react' ; import LazilyRender from 'react-lazily-render' ; ...lots of content... < LazilyRender xss=removed> } content = { ...
Apply the core principles of concurrency to both browser and server side development Explore the latest tools and techniques at the forefront of concurrent programming, including JavaScript promises, ...
How to get the most out of this book Conventions Assumptions for every recipe Dataset Descriptions Sections Getting ready How to do it... How it works... There's more... See also Reader feedback ...
Exporting a lazily initialized bean (which implements SelfNaming and is annotated with ManagedResource annotation) gives IllegalStateException [SPR-17592] #22124 MockHttpServletRequest changes Accept-...
9.3 Starting bundles lazily 314 Understanding activation policies 315 ■ Using activation policies 316 9.4 Summary 317 10 Managing applications 319 10.1 Deploying bundles 320 Introducing management ...
lazily. Copyright (c) 2009 Armando Blancas. All rights reserved. The use and distribution terms for this software are covered by the Eclipse Public License 1.0 ...
// Subscribes to a Pub/Sub channel using the internal, lazily initialized SubscriberClient redis.subscriber.subscribe("My Channel") { case message @ PubSubMessage.Message(channel, ...
懒惰地ReactIMG React Lazily IMG是一个React Wrapper组件,用于延迟加载图像。 目标是使用方便且已知的标准HTML标记,并只是延迟加载它们。特征图片标签和IMG srcset支持Webp检测占位符HTML && CSS图像支持下载图像...
/ Errrrr...Actually, I hesitate to release the source code of this control, / Because when I checked after completion, I found that it's really ugly! Putting all / graphic codes in the CDraw class ...
-- data-qazy is set to true means to load it lazily. Set it to false if you don't want to load it lazily. --> <!-- A default placeholder is used. To change the placeholder, assign the variable ...
The aim is to provide, lazily evaluated, pull-based datastream support with the same naming as in RxJava mainly for the pre-Java-8 world. The Stream API in Java 8 is not exactly the same thing because...
获取所有文件 具有延迟同步和异步迭代器支持的出色的快速递归目录搜寻器。 安装 支持Node.js版本10及更高版本。 $ npm i get-all-files 用法 import getAllFiles from ... // Could break early on some condition a
Kodein is a very simple and yet very useful dependency retrieval container. it is very easy to use and configure. Kodein works: On the JVM. On Android. On Javascript (both in the browser and on Node....
名称 Cinnamon-简约的部署工具 概要 use strict; use warnings; # Exports some commands use Cinnamon::DSL; my $application = 'My::App';...# Lazily evaluated if passed as a code set lazy_value => sub { #.
“A ViewStub is an invisible, zero-sized View that can be used to lazily inflate layout resources at runtime. When a ViewStub is made visible, or when inflate() is invoked, the layout resource is ...
A way to think about system design Could I do this lazily/speculatively? When would it pay?Steps toward a sound theory of laziness or speculationI am not presenting such a theory12 December 2006 ...
已缓存 一个简单的缓存库,受启发,偏向于。 该接口仅公开了非常有限的功能,没有对缓存数据的多次获取或删除。...// Set a key using a lazily created promise (or value) kittens . set ( 'my.key' , function
Will be lazily created when running layout tests.namespace content.