dubbo序列化,hibernate.LazyInitializationException could not initialize proxy - no Session懒加载异常的解决 转

JPA 中 LazyInitializationException 解决方案 阅读详情

dubbo序列化,hibernate.LazyInitializationException could not initialize proxy - no Session懒加载异常的解决

 

转载声明:请务必保留原文链接

原文连接:http://www.cnblogs.com/sunyl/p/7772260.html

 

版本

1.JDK 1.8

2.Spring Boot ,spring boot jpa 1.5.8

3.dubbo 2.5.6

4.zookeeper 3.4.9

 

异常说明:

使用dubbo作为RPC框架时 发现如果有实体对象有懒加载属性会出现如下异常,我在设 #spring.jpa.open-in-view=true未能解决。

Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: cn.syl.blogmain.pojo.User.roles, could not initialize proxy - no Session
at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:587)
at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:204)
at org.hibernate.collection.internal.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:148)
at org.hibernate.collection.internal.PersistentSet.size(PersistentSet.java:143)
at com.alibaba.com.caucho.hessian.io.CollectionSerializer.writeObject(CollectionSerializer.java:92)
at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:383)
at com.alibaba.com.caucho.hessian.io.JavaSerializer$FieldSerializer.serialize(JavaSerializer.java:294)
... 29 more

 

三种解决方法:

原因是dubbo使用的序列化hessian 对PersistentCollection对象无法识别,有如下三种解决方法:

1.JPA Hibernate禁止懒加载

2.添加自定义dubbo序列化工厂(请参考:http://wzalong.iteye.com/blog/2323787)

3.修改dubbo序列化方式:<dubbo:protocol name="dubbo" port="20880" serialization="java" />

 

由于本人对dubbo研究甚少少 所以目前采用了第三种方式. 

如有高人使用了第二种自定义序列化工厂或其他更好的方式 还请指教,我不太清楚dubbo自定义序列化工厂如何配置.

 

可参考的项目配置(仅包含配置的项目,集成:spring boot +dubbo +redis +jpa+shiro): 

如果项目对您有帮助请给我一颗star.谢谢~

https://github.com/mmdsyl/BLOG-Microservice/

TongWeb做session复制报错Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize 🏆 本文收录于《全栈Bug调优(实战版)》专栏,致力于分享我在项目实战过程中遇到的各类Bug及其原因,并提供切实有效的解决方案。无论你是初学者还是经验丰富的开发者,本文将为你指引出一条更高效的Bug修复之路,助你早日登顶,迈向财富自由的梦想🚀!同时,欢迎大家关注、收藏、订阅本专栏,更多精彩内容正在持续更新中。让我们一起进步,Up!Up!Up!    备注: 部分问题/难题源自互联网,但经过精心筛选和整理,保证每一条解决方案都经过实战验证,真实可靠。 阅读详情

相关推荐

MobaXterm隧道配置详解:为PyCharm远程开发打通‘最后一公里’

本文详细解析了如何利用MobaXterm配置SSH隧道,实现PyCharm远程开发的高效连接。通过本地端口转发技术,开发者可以安全访问内网服务器,特别适用于需要通过跳板机的复杂网络环境。文章涵盖从基础配置到企业级运维的全套解决方案,包括性能优化、安全加固等实用技巧。

weixin_30566063的博客 503

【org.hibernate.LazyInitializationException: failed to lazily initialize】问题解决

报错: org.hibernate.LazyInitializationException: failed to lazily initialize XXXXX could not initialize proxy - no Session 解决: 这个问题是由于实体中一对多或者多对多关联关系的加载方式配置不当引起的。 一对多或者多对多关联关系的加载策略使用了懒加载,结果在加载子实体时就会报 o...

烂牙大叔 8234

TCGA数据集介绍及数据下载指南(新手友好篇)

目录一、TCGA数据集介绍1.1 数据集介绍1.2 File介绍1.2.1 Data Category(数据类别)1.2.2 Data Type(数据类型)1.2.3 Experimental Strategy(实验策略)1.2.4 Workflow Type(工作流类型)1.2.5 Data Format(数据格式)1.2.6 Platform(平台)1.2.7 Access1.3 Cases介绍1.3.1 Case ID(案例编号)1.3.2 Primary Site(主要站点)1.3.3 Progra

Wendy的博客 6万+

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role 延迟加载异常解决

问题描述 在使用spring data jpa的关联关系时,使用了【延迟加载】方式,导致后续查询关联属性时,抛出LazyInitializationException。 问题分析 spring data jpa中,@OneToOne默认为fetch=fetchType.eager,这是不采用延迟加载的方式,而@ManyToMany 默认为 fetch=fetchType.lazy,默认为延迟加载方式。 导致这种错误出现的原因,就是延迟加载。那么,为什么延迟加载会导致无法再次查询数据库了呢? 我们把错误信息来

InterestAndFun的博客 4549

银河麒麟V10 SP1忘记密码?3分钟搞定单用户模式密码重置(附详细截图)

本文详细介绍了银河麒麟V10 SP1操作系统忘记登录密码后的应急恢复方法。核心是通过GRUB引导菜单进入单用户模式,无需密码即可获得root权限,从而快速重置用户密码。文章提供了从捕捉GRUB界面、编辑启动参数到执行密码修改命令的完整步骤图解与常见问题解决方案,帮助用户在几分钟内恢复系统访问。

w3x4y的博客 916

Hive数据迁移

【迁移背景】 本次需要将老集群的hive数据(共30多张表)迁移至新集群中。 老集群版本为CDH5.13,未启用kerberos; 新集群版本为CDH5.14,启用了kerberos。 由于cloudera官方文档说明,在5.x的版本不支持从未启用kerberos的集群与启用了kerberos的集群之间的数据复制。因此无法通过bdr方式进行数据同步。于是采用手工方式进行测试验证。 第一步...

wangkuangood3200的专栏 469

解决:org.hibernate.LazyInitializationException: failed to lazily initialize(2013-04-28 14:49:47)

原因是在hibernate映射关系中由于延迟加载,session在调用前已经被关闭,,所以加载set属性时无可用session 解决方案: 在 @ManyToOne端设置fetch=FetchType.LAZY,@OneToMany端设置fetch=FetchType.EAGER,如下配置 @ManyToOne(cascade={CascadeType.REFRESH, Casc

cuibruce的博客 858

基于Python实现的捕鱼达人小游戏源代码+使用说明

摘要: 本文介绍了一款自制的捕鱼达人小游戏,使用Python3和Pygame模块开发。游戏包含完整的资源文件(图片、音效、字体)和源码结构(11个功能模块),实现了大炮移动射击、特殊子弹、炸弹、难度递增等核心玩法。安装需配置Python环境和Pygame模块,运行main.py即可启动游戏。游戏支持键盘控制(方向键移动、空格射击、1键放炸弹),默认时长600秒,包含开始菜单、游戏界面和结束界面。所有代码均有详细注释,项目已开源并提供下载链接。(150字)

2301_76484015的博客 667

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.mar

实体配置懒加载时遇到的异常情况 org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.markix.entity.po.UserPO.roles, could not initialize proxy - no Session at org.hibernate.collection.internal.AbstractPersistentCollection.thro

Markix的博客 1597

QT使用高精度定时器

精度相对第二种方法高许多。

ljjjjjjjjjjj的博客 4097

org.hibernate.LazyInitializationException(懒加载异常)原因

could not initialize proxy - no Session在&lt;many-to-on&gt;中这错误很常见,字面意义就是不能被初始化,因为session已经关闭了。简单理解就是因为,你使用了lazy=true,这样hibernate在从数据库中调数据的时候是不会把关联的对象查出来的,而是保存一个获取值得方法,在你使用getXXX()调用的时候,hiberante会利用这个保...

kahhy的博客 1万+

爬虫:一文掌握网站加密和混淆以及浏览器调试的技巧

面对加密和混淆技术的网站,传统的爬虫方法可能难以奏效。通过结合浏览器调试工具(如Puppeteer、Playwright)、代理工具(如Burp Suite、Fiddler)以及动态和静态分析技巧,可以深入理解网站的运行机制,绕过加密和混淆,实现有效的数据抓取。同时,务必注意合法合规,尊重目标网站的规则和用户的隐私,确保爬虫行为的正当性和可持续性。

数据知道的博客 9891

dubbo序列化hibernate.LazyInitializationException could not initialize proxy - no Session懒加载异常的解决

dubbo序列化hibernate.LazyInitializationException could not initialize proxy - no Session懒加载异常的解决

qq_38472574的博客 186

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

dubbo序列化hibernate.LazyInitializationException could not initialize proxy - no Session懒加载异常的解决...

dubbo序列化,hibernate.LazyInitializationException could not initialize proxy - no Session懒加载异常的解决 转载声明:请务必保留原文链接 原文连接:http://www.cnblogs.com/sunyl/p/7772260.html 版本 1.JDK 1.8 2.Spring Boot ,sp...

weixin_30810583的博客 305

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

org.hibernate.LazyInitializationException: failed to lazily initialize

今天搞了一上午,都在解决这个问题:org.hibernate.LazyInitializationException: failed to lazily initialize 原因很简单,是在非法的session中去调用lazy=“true“的属性, 网上资料蛮多的,解决方法有两个 1,把lazy=”false“ 2,在web.xml中加入:(在structs的过滤器之前) <...

weixin_30898109的博客 399

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Hibernate异常之:failed to lazily initialize a coll...

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34363171的博客 425

org.hibernate.LazyInitializationException异常解决办法

org.hibernate.LazyInitializationException异常 failed to lazily initialize a collection...的解决方案 使用hibernate从一方获取多方信息的时候发生 org.hibernate.LazyInitializationException: failed to lazily initialize a colle...

一一哥 1万+

hibernate—懒加载问题解决

错误: Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: cn.bos.domain.base.Courier.fixedAreas...

246

Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of ro

解决方式:对多集合数据懒加载问题,排除掉关联集合数据转换 json添加一个注解 @JSON(serialize = false)  在实体类中的集合的get方法上添加 即可 要是maven工程 最后记得install...

qq_37593628的博客 573

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role

报错信息: description The server encountered an internal error that prevented it from fulfilling this request. exception org.springframework.http.converter.HttpMessageNotWritableException: Could not write...

icecoola_的博客 1416

解决: failed to lazily initialize a collection of role: XXX, could not initialize proxy - no Session

failed to lazily initialize a collection of role: XXXXXXXX, could not initialize proxy - no Session问题解决方案

vaNaVnVan的博客 5118

failed to lazily initialize a collection of role

因为有的时候我们使用JPA的时候由于某个实体的属性数据量比较大所以使用延迟加载来优化,而在struts2的action中使用到实体的时候却因为实体管理器已经关闭实体成为游离态,且数据延迟加载导致没有加载我们所需要的数据,比如: [java] view plaincopyprint? @OneToMany(cascade = { CascadeType.REFRESH,

说:/~不了的专栏 7196

Hibernate开发中常见错误总结

org.hibernate.MappingException: Unknown entity: cn.itcast.hibernate717.helloworld.Person hibernate框架根本不知道Person这个持久化类的存在 Caused by: java.sql.SQLException: Field 'id' doesn't have a default value 如果

涂作权的博客 3万+
上一篇: Spring Boot打包war jar 部署tomcat
下一篇: 网站集成微软账户一键登录(支持Windows Hello 面容、指纹等)-微软Azure的Oauth2.0的集成
sunkes
博客等级 码龄16年 5粉丝 8原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值