hibernate一对多出现failed to lazily initialize a collec
转自:http://yang7527.iteye.com/blog/432066
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>
这样就会执行一条表连接语句,避免问题的出现
分享到:
相关推荐
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 = { ...
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 ...
懒惰地ReactIMG React Lazily IMG是一个React Wrapper组件,用于延迟加载图像。 目标是使用方便且已知的标准HTML标记,并只是延迟加载它们。特征图片标签和IMG srcset支持Webp检测占位符HTML && CSS图像支持下载图像...
Exporting a lazily initialized bean (which implements SelfNaming and is annotated with ManagedResource annotation) gives IllegalStateException [SPR-17592] #22124 MockHttpServletRequest changes Accept-...
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 ...
// Subscribes to a Pub/Sub channel using the internal, lazily initialized SubscriberClient redis.subscriber.subscribe("My Channel") { case message @ PubSubMessage.Message(channel, ...
- **.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...
-- 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 ...
3. 冠词:"a good worker",不定冠词a用于表示泛指,此处表示“一个好工人”。 4. 形容词与过去分词的区别:"Although surprised",形容词surprised用于表示人的感受。 5. 连词:"because he really needed help",...
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....
- 完成句子练习可以帮助巩固词汇的应用,如:"The young man rose lazily and was not willing to greet us."(年轻人懒洋洋地起身,并不愿意向我们打招呼。),"This appointment was greeted with relief."(这个...
名称 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 { #.
stream.js 是一个很小、完全独立的Javascript类库,它为你提供了一个新的Javascript数据结构:streams.Streams 是一个操作简单的数据结构,很像数组或链接表,但附加了一些非凡的能力。跟数组不一样,streams是一个...
`lazily`:金鱼慵懒地(lazily)成群结队地在水面下游动。 - 15. `coats`:他们给前门刷了三层(coats)油漆。 2. **关键短语或词组**: - 1. `come along`:一起来,过来。 - 2. `a novel called…`:一本叫做...
- **例句:** 我在厨房里找到了一盒火柴 (a box of matches),准备用来点蜡烛。 2. **围裙 (apron)** - **定义:** 一种穿戴于胸前,用于保护衣物免受污损的布料。 - **例句:** 一位身穿白色围裙 (white apron)...
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 ...
这篇文档是针对八年级英语学习的一份测试卷,主要涵盖了词汇、语法和句型等多个方面的知识点,旨在检验学生对英语基础知识的掌握程度。下面将详细阐述这些知识点: **词汇部分:** 1. 动词的现在分词变化,如...
这篇PPT课件是关于新概念英语第一册第109-110课的内容,主要涉及形容词比较级和最高级的用法,以及一些相关的词汇和表达。以下是详细的知识点讲解: 1. 形容词比较级和最高级的基本形式: - 对于单音节形容词,如...
该接口仅公开了非常有限的功能,没有对缓存数据的多次获取或删除。 该库旨在支持不同的缓存后端,尽管目前仅实现了memcached。 它支持基于promise和基于回调的用法。 安装 npm install --save cached 用法 下一节...