`
wxinpeng
  • 浏览: 581722 次
  • 性别: Icon_minigender_1
  • 来自: 青岛
社区版块
存档分类
最新评论

hibernate一对多出现failed to lazily initialize a collec

阅读更多

hibernate一对多出现failed to lazily initialize a collection of role异常!

1.这是关于延迟加载的问题
    <set name="news" inverse="true">            
           <key column="typeId"></key>           
           <one-to-many class="com.auj.sshdemo.bean.News"/>     
     </set>  
改成:
  <set name="news" inverse="true" cascode="all" lazy="false">            
           <key column="typeId"></key>           
           <one-to-many class="com.auj.sshdemo.bean.News"/>     
     </set>

cascode="all"
这也就使用了级联,代表在你查询主表的数据的时候,也去查询子表的数据。设置成all也就代表对主表的select,delete,update,save的时候,也要对进行相应的操作。在hibernate的session在假如以查询来讲,当你查询了主表的完成后,session关闭。这是字表的数据没有去数据库中查询。所以会报错!
lazy="false”
加上这个也就代表了非延迟加载,这样session也就不会关闭。


cascode的设置要根据需要使用,主要是考虑效率问题!
解决方案二:
<set name="news" inverse="true" cascode="all"  fetch="join">            
           <key column="typeId"></key>           
           <one-to-many class="com.auj.sshdemo.bean.News"/>     
     </set>
这样就会执行一条表连接语句,避免问题的出现
分享到:
评论

相关推荐

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

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

    Python Cookbook英文版

    1.4 Adding an Entry to a Dictionary 1.5 Associating Multiple Values with Each Key in a Dictionary 1.6 Dispatching Using a Dictionary 1.7 Collecting a Bunch of Named Items 1.8 Finding the ...

    Pandas Cookbook 2017 pdf 2分

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

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

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

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

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

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

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

    OSGI in Action

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

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

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

    stream.js Javascript

    stream.js 是一个很小、完全独立的Javascript类库,它为你提供了一个新的Javascript数据结构:streams.Streams 是一个操作简单的数据结构,很像数组或链接表,但附加了一些非凡的能力。跟数组不一样,streams是一个...

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

    node-cached:受Play缓存API启发的用于node.js的简单缓存库

    该接口仅公开了非常有限的功能,没有对缓存数据的多次获取或删除。 该库旨在支持不同的缓存后端,尽管目前仅实现了memcached。 它支持基于promise和基于回调的用法。 安装 npm install --save cached 用法 下一节...

    Android组件ViewStub基本使用方法详解

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

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

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

    Android代码-ixjava

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

    Free Hex Control

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

    Lazy and Speculative Execution - Microsoft Research - Slides (12th December, 2006)-计算机科学

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

Global site tag (gtag.js) - Google Analytics