今天在维护项目维护开发过程中出了个问题。
报错是:“ Failed to lazily initialize a collection - no session or session was closed”一看这个错误就知道是lazyLoad问题。
先在网上找了相关问题解决方式,在转载的文章中(http://wujt.iteye.com/admin/blogs/433788)学习一把Hibernate与延迟加载原理。
在映射文件中“
<bag name="keywordInfos" lazy="true" inverse="false" cascade="all-delete-orphan">
<key column="ACCEPT_RECORD_ID"/>
<one-to-many class="com.hollycrm.unicom.sheet.lightweight.AcceptKeywordInfo"/>
</bag>”
一般解决方式是 lazy="true"该为 lazy="false";
但是这个字段在其他地方用到,是否会影响到其他地方的效率问题不能确认;
参照(http://wujt.iteye.com/admin/blogs/433799)提供的第二种方法解决:
对于查询中如果用的是xxx.load(class,id)则改为xxx,get(class,id)
还是报“ Failed to lazily initialize a collection - no session or session was closed”错误;
便采用地三种方法解决:
HibernateTemplate ht = getHibernateTemplate();
MainSheet mainSheet = (MainSheet) ht.load(MainSheet.class,id);
mainSheet.getKeywords().size();//将延时加载的对象加载一遍
return mainSheet;
在使用Keywords正常,不会报“ Failed to lazily initialize a collection - no session or session was closed”错误。
问题解决OK。
分享到:
相关推荐
committed, the command line prompt script failed to notice the current status, which has been improved. * Many GIT_TEST_* environment variables control various aspects of how our tests are run, ...
npm install --save react-lazily-render 用法 () import React from 'react' ; import LazilyRender from 'react-lazily-render' ; ...lots of content... < LazilyRender xss=removed> } content = { ...
- **.NET as a Reaction to the Java World**: Microsoft’s response to Sun Microsystems’ Java platform, aiming to provide a robust framework for building and running applications. - **The Open Source...
Slicing rows lazily Getting ready How to do it... How it works... There's more... Slicing lexicographically Getting ready How to do it... How it works... There's more... 5. Boolean Indexing ...
Understand exactly how JavaScript works in a web browser environment and how these mechanisms power our event-driven JavaScript code Use promises to turn complex synchronization scenarios into ...
Exporting a lazily initialized bean (which implements SelfNaming and is annotated with ManagedResource annotation) gives IllegalStateException [SPR-17592] #22124 MockHttpServletRequest changes Accept-...
// 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图像支持下载图像...
-- 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 ...
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 { #.
- 完成句子练习可以帮助巩固词汇的应用,如:"The young man rose lazily and was not willing to greet us."(年轻人懒洋洋地起身,并不愿意向我们打招呼。),"This appointment was greeted with relief."(这个...
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 ...
3. 冠词:"a good worker",不定冠词a用于表示泛指,此处表示“一个好工人”。 4. 形容词与过去分词的区别:"Although surprised",形容词surprised用于表示人的感受。 5. 连词:"because he really needed help",...
“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 ...
获取所有文件 具有延迟同步和异步迭代器支持的出色的快速递归目录搜寻器。 安装 支持Node.js版本10及更高版本。 $ npm i get-all-files 用法 import getAllFiles from ... // Could break early on some condition a
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...
`lazily`:金鱼慵懒地(lazily)成群结队地在水面下游动。 - 15. `coats`:他们给前门刷了三层(coats)油漆。 2. **关键短语或词组**: - 1. `come along`:一起来,过来。 - 2. `a novel called…`:一本叫做...
/ specific area difficult, so I lazily redraw almost the whole control whenever / it needs. This results in the slowness (I suggest you can use the control in data / display, ^_^). In next version,...
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 ...