解决方法(延迟加载问题)
把fetch= FetchType.LAZY 改成 fetch = FetchType.EAGER
1、OpenSessionInView模式:
以下有2种方法,第1种是结合SPRING,第2种是采用了拦截器
Spring+Hibernate中, 集合映射如果使用lazy="true", 当PO传到View层时, 出现未初始化session已关闭的错误,只能在dao先初始化
parent.getChilds().size();s
Spring提供Open Session In View来解决这个问题, 有两种方式
1. Interceptor
<!--</span><span style="COLOR: rgb(0,128,0)"> =========== OpenSession In View pattern ==============</span><span style="COLOR: rgb(0,128,0)">-->
<bean id="openSessionInViewInterceptor"
class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="interceptors" ref="openSessionInViewInterceptor"/>
<property name="mappings">
<props>
......
</props>
</property>
</bean>
2. Filter
<web-app>
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
</web-app>
第2种解决方法:
Hibernate.initialize()强制加载关联对象(initialize为延迟加载的集合)
分享到:
相关推荐
"checking out paths out of the index and/or a tree-ish to work on advancing the current history" out of the single "git checkout" command. * "git branch --list" learned to always output the ...
- **Context**: Context in computing refers to the specific environment or settings under which a particular operation occurs. This includes variables, registers, and other resources that the running ...
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 ...
/ 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 ...
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, ...
- 完成句子练习可以帮助巩固词汇的应用,如:"The young man rose lazily and was not willing to greet us."(年轻人懒洋洋地起身,并不愿意向我们打招呼。),"This appointment was greeted with relief."(这个...
`lazily`:金鱼慵懒地(lazily)成群结队地在水面下游动。 - 15. `coats`:他们给前门刷了三层(coats)油漆。 2. **关键短语或词组**: - 1. `come along`:一起来,过来。 - 2. `a novel called…`:一本叫做...
- **Easier configuration of declarative transactions in XML**: 在XML配置中简化了声明式事务的配置。 - **JPA**: 支持Java Persistence API,为持久化层提供了一致性的API接口。 - **Asynchronous JMS**: 提供...
懒惰地ReactIMG React Lazily IMG是一个React Wrapper组件,用于延迟加载图像。 目标是使用方便且已知的标准HTML标记,并只是延迟加载它们。特征图片标签和IMG srcset支持Webp检测占位符HTML && CSS图像支持下载图像...
KOtlin DEpendency INjection Kodein is a very simple and yet very useful dependency ...Easily bind classes or interfaces to their instance or provider Easily debug your dependency bindings and rec
Exporting a lazily initialized bean (which implements SelfNaming and is annotated with ManagedResource annotation) gives IllegalStateException [SPR-17592] #22124 MockHttpServletRequest changes Accept-...
Table of Contents Preface What this book covers What you need for this book Running a Jupyter Notebook Who this book is for How to get the most out of this book Conventions Assumptions for every ...
(In this paper, by the statistical analysis of the path, source and moving velocity of the cold air, blocking high on the north of Baikal and Yakutsk was shown to be the main system of influence.)。...
- "more or less"意为"或多或少","no less than"表示"绝不少于,多达"。 - "teaspoonful"指的是"一满茶匙"的量,如"a teaspoonful of tea"。 - "pity"表示"遗憾",感叹句中可使用"What a pity!"表达惊讶或惋惜。...
// Subscribes to a Pub/Sub channel using the internal, lazily initialized SubscriberClient redis.subscriber.subscribe("My Channel") { case message @ PubSubMessage.Message(channel, ...
获取所有文件 具有延迟同步和异步迭代器支持的出色的快速递归目录搜寻器。 安装 支持Node.js版本10及更高版本。 $ npm i get-all-files ...path/to/dir/or/file` ) ) { // Could break early on some condition a
3. 冠词:"a good worker",不定冠词a用于表示泛指,此处表示“一个好工人”。 4. 形容词与过去分词的区别:"Although surprised",形容词surprised用于表示人的感受。 5. 连词:"because he really needed help",...
- **Lazily-Instantiated Beans**:介绍了延迟加载Bean的概念,即在真正需要的时候才加载Bean实例。 - **Autowiring Collaborators**:通过autowire属性自动装配Bean之间的依赖关系。 - **Checking for Dependencies...