`

ERROR LazyInitializationException:42 - failed to lazily initialize a collection

阅读更多

ERROR LazyInitializationException:42 - failed to lazily initialize a collection of role: com.lixueli.business.model.Person.events, no session or session was closed

 

在配置文件中加入lazy="false"即可

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
  <class name="com.lixueli.business.model.Person" table="person">
    <id name="id" column="PERSON_ID">
    	<generator class="native"></generator>
    </id>
    <property name="age"></property>
    <property name="firstName"></property>
    <property name="lastName"></property>
     <set name="events" table="PERSON_EVENT" lazy="false">
     	<key column="PERSON_ID"></key>
     	<many-to-many column="EVENT_ID" class="com.lixueli.business.model.Event"></many-to-many>
     </set>
  </class>
  
</hibernate-mapping>

 

分享到:
评论
1 楼 yoin528 2011-01-23  
懒加载异常你真的觉得不用懒加载就好了么,这样不是对这个设计冲突了么??
在hibernate 里面web.xml可以配置org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
防止懒加载
在jpa里面可以注解
@PersistenceContext(type=PersistenceContextType.EXTENDED)

我觉得这种方式更好。

相关推荐

    JavaScript Concurrency pdf 无水印 0分

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

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

    Packt.Mastering.Csharp.and.NET.Programming

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

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

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

    Git-2.21.0-64-bit.zip

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

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

    - 完成句子练习可以帮助巩固词汇的应用,如:"The young man rose lazily and was not willing to greet us."(年轻人懒洋洋地起身,并不愿意向我们打招呼。),"This appointment was greeted with relief."(这个...

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

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

    特征图片标签和IMG srcset支持Webp检测占位符HTML && CSS图像支持下载图像时的第一个渲染自定义可见性百分比渲染图像时的自定义回调安装npm install react-lazily-img --save 演示版即将推出。它是如何工作的 ? ...

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

    spring-reference

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

    前端面试-v21

    - ` Lazily loaded images`:利用`loading="lazy"`属性延迟加载图片。 开放式问题涉及的技能和流程,如JavaScript延迟加载技术、关注的技术趋势、开发流程与使用的工具、网站性能优化策略、原型继承和闭包的理解等...

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

    - 以辅音字母+y结尾的词,如"lazily",改y为i再加"-er/est",形成"lazier"和"laziest"。 - 以不发音的e结尾的形容词,如"large",直接加"-r/-st",得到"larger"和"largest"。 - 多音节和某些双音节词,如...

    spring-reference.pdf

    - **Lazily-instantiated beans**: 延迟加载Bean,直到第一次请求时才初始化。 - **Autowiring collaborators**: 自动装配协作对象,简化了配置。 - **Checking for dependencies**: 检查Bean是否存在未满足的依赖。...

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

    - **例句:** 他伸了伸懒腰,打了个哈欠 (he stretched and yawned lazily)。 13. **壮丽的 (splendid)** - **定义:** 形容宏伟壮观的事物。 - **例句:** 这座宫殿非常豪华 (splendid palace)。 14. **一道菜...

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

    广东省广州市2018年中考英语学科模拟题十六20180709274

    3. 冠词:"a good worker",不定冠词a用于表示泛指,此处表示“一个好工人”。 4. 形容词与过去分词的区别:"Although surprised",形容词surprised用于表示人的感受。 5. 连词:"because he really needed help",...

    get-all-files::high_voltage:具有懒惰同步和异步迭代器支持的快速递归目录搜寻器

    获取所有文件 具有延迟同步和异步迭代器支持的出色的快速递归目录搜寻器。 安装 支持Node.js版本10及更高版本。 $ npm i get-all-files 用法 import getAllFiles from ... // Could break early on some condition a

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

Global site tag (gtag.js) - Google Analytics