`

failed to lazily initialize a collection of role:

阅读更多
failed to lazily initialize a collection of role:
转自:http://blog.163.com/nikyok/blog/static/5550845320076261143867/
环境 spring+hibernate3+struts

今天又碰到错误

failed to lazily initialize a collection ofrole: no session or session was closed

试验了一下发现了几个解决方法:

1、是把对应一对多的那两个列lazy=true改为lazy=false即可

2、对于查询中如果用的是xxx.load(class,id)则改为xxx,get(class,id)
3在web.xml文件中加入

<filter>
  <filter-name>hibernateFilter</filter-name>
  <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>

  <init-param>
           <param-name>singleSession</param-name>
           <param-value>false</param-value>
       </init-param>

<!--这个--  <init-param>一定要加不然很可能会报错:org.springframework.dao.InvalidDataAccessApiUsageException:Write operations are not allowed in read-only mode(FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove'readOnly' marker from transaction definition
>
</filter>

<filter-mapping>
  <filter-name>hibernateFilter</filter-name>
  <url-pattern>*.mmg</url-pattern>
</filter-mapping>
分享到:
评论
4 楼 zhoulongbin 2009-09-14  
感谢楼主,第一种方法解决了我的问题,但是我不明白,在class里面我已经设置了lazy=false了,为什么在一对多的列里面还需要设置,hibernate机制是如何处理这种一对多和多对一关系,可以给我说说嘛?我是初学者,谢谢了
3 楼 yueliangwolf 2009-09-02  
用你的第三个方法,结果:
net.sf.dozer.util.mapping.MappingException: java.lang.StackOverflowError
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:77)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:196)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter

似乎是我的dozer有问题,但是。。。。
2 楼 yueliangwolf 2009-09-02  
但是一对多如果lazy="true",就会出session已关闭错误,没法活了。。。
1 楼 yueliangwolf 2009-09-02  
我用你的第一个办法,结果:
java.lang.StackOverflowError
at java.lang.Exception.<init>(Exception.java:59)
at java.lang.ClassNotFoundException.<init>(ClassNotFoundException.java:65)
at java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.lang.ClassLoader.findBootstrapClass0(ClassLoader.java:892)
at java.lang.ClassLoader.loadClass(ClassLoader.java:302)
at java.lang.ClassLoader.loadClass(ClassLoader.java:300)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
。。。。。。。。。。。。。。。

相关推荐

    Packt.Mastering.Csharp.and.NET.Programming

    - **A Quick Tip on the Execution and Memory Analysis of an Assembly in Visual Studio 2015**: Using tools like the Visual Studio Profiler to analyze the memory usage and performance of .NET ...

    Git-2.21.0-64-bit.zip

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

    react-lazily-render:延迟安装昂贵的组件,直到将占位符组件滚动到视图中为止

    npm install --save react-lazily-render 用法 () import React from 'react' ; import LazilyRender from 'react-lazily-render' ; ...lots of content... &lt; LazilyRender xss=removed&gt; } content = { ...

    Android代码-clojure-jsr223

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

    广东省深圳市文汇中学2015届九年级英语上学期第7周周末作业(答案不全) 牛津深圳版

    `lazily`:金鱼慵懒地(lazily)成群结队地在水面下游动。 - 15. `coats`:他们给前门刷了三层(coats)油漆。 2. **关键短语或词组**: - 1. `come along`:一起来,过来。 - 2. `a novel called…`:一本叫做...

    JavaScript Concurrency pdf 无水印 0分

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

    react-lazily-img:React Wrapper组件使用IntersectionObserver API延迟加载图像

    懒惰地ReactIMG React Lazily IMG是一个React Wrapper组件,用于延迟加载图像。 目标是使用方便且已知的标准HTML标记,并只是延迟加载它们。特征图片标签和IMG srcset支持Webp检测占位符HTML && CSS图像支持下载图像...

    Free Hex Control

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

    spring-net-reference.pdf

    - **Setting a reference using the members of other objects and classes**:演示了如何通过其他对象或类的成员设置引用。 - **Provided IFactoryObject implementations**:列出了一些预定义的`IFactoryObject`...

    springframework.5.0.12.RELEASE

    Exporting a lazily initialized bean (which implements SelfNaming and is annotated with ManagedResource annotation) gives IllegalStateException [SPR-17592] #22124 MockHttpServletRequest changes Accept-...

    Pandas Cookbook 2017 pdf 2分

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

    2019_2020学年高中英语Unit4BodyLanguageperiod2WarmingUp&Reading2课件新人教版必

    例如,"After about ten minutes of waiting, I saw a middle-aged man enter her courtyard looking back carefully."中,"After about ten minutes of waiting"作为时间状语,描述动作发生的时间;"looking back ...

    Android代码-Kodein-DI

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

    spring-reference.pdf

    - **Easier configuration of declarative transactions in XML**: 在XML配置中简化了声明式事务的配置。 - **JPA**: 支持Java Persistence API,为持久化层提供了一致性的API接口。 - **Asynchronous JMS**: 提供...

    Redis的Scala客户端Scredis.zip

    // Subscribes to a Pub/Sub channel using the internal, lazily initialized SubscriberClient redis.subscriber.subscribe("My Channel") {  case message @ PubSubMessage.Message(channel, ...

    spring-reference

    - **Lazily-Instantiated Beans**:介绍了延迟加载Bean的概念,即在真正需要的时候才加载Bean实例。 - **Autowiring Collaborators**:通过autowire属性自动装配Bean之间的依赖关系。 - **Checking for Dependencies...

    初中英语第六册(北京版)

    - **例句:** 我在厨房里找到了一盒火柴 (a box of matches),准备用来点蜡烛。 2. **围裙 (apron)** - **定义:** 一种穿戴于胸前,用于保护衣物免受污损的布料。 - **例句:** 一位身穿白色围裙 (white apron)...

    cinnamon:一个简单的部署工具

    名称 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 =&gt; sub { #.

    Qazy:延迟加载 - 没有 SEO 负面影响

    -- data-qazy is set to true means to load it lazily. Set it to false if you don't want to load it lazily. --&gt; &lt;!-- A default placeholder is used. To change the placeholder, assign the variable ...

    新概念英语第一册第109-110课PPT课件.pptx

    - "advice"意为"建议",常搭配"a piece of advice",动词形式如"give advice", "act on sb's advice"等。 4. 替代和程度副词: - "instead"表示"代替",如"There isn't any cigarette, have a biscuit instead....

Global site tag (gtag.js) - Google Analytics