mybatis non transactional SqlSession的解决

Spring+Mybatis整合事务不起作用之解决方案汇总 前言: 公司最近一个项目用到Spring和Mybatis,发现用起来挺方便,比以前的那个struts+hibernate舒服多了。废话少说,直接摆问题,碰到的问题是,mybatis不在事务中运行,后台日志报 “Closing no transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1 阅读详情

      这个问题有两种解决方案:第一种是通过给方法加上@Transactional注解并且给配置中加入事务扫描<tx:annotation-driven transaction-manager="transactionManager"/>

                                                       第二种是通过配置来实现事务的同步。例如:

     <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="datasource"/>
    </bean>
    <!-- - - - - - - spring 事务属性 - - - - - - - -->
    <tx:advice id="transactionAdvice" transaction-manager="transactionManager">
    <tx:attributes>
      <tx:method name="delete*" propagation="REQUIRED"  read-only="false" 
                            rollback-for="Exception" no-rollback-for="RuntimeException"/>
      <tx:method name="insert*" propagation="REQUIRED" read-only="false" 
                            rollback-for="java.lang.RuntimeException"  />
      <tx:method name="update*" propagation="REQUIRED" read-only="false" 
                            rollback-for="java.lang.Exception" />
      <tx:method name="select*" propagation="SUPPORTS"/>
      <tx:method name="save*"  propagation="REQUIRED" read-only="false" rollback-for="Exception" />
      <tx:method name="remove*"  propagation="REQUIRED" read-only="false" rollback-for="Exception" />
      <tx:method name="add*"  propagation="REQUIRED" read-only="false" rollback-for="Exception" />
      <tx:method name="up*"  propagation="REQUIRED" read-only="false" rollback-for="Exception" />
    </tx:attributes>
    </tx:advice>
    <!--******    织入,请修改成实际的业务层包名  *********-->
    <aop:config>
        <aop:advisor advice-ref="transactionAdvice" pointcut="execution(* com.ha.service.*.*(..))"/>
    </aop:config>

   这种方式,出问题的位置在于 <aop:advisor advice-ref="transactionAdvice" pointcut="execution(* com.ha.service.*.*(..))"/>这句话,主要在于pointcut后面的表达式有问题,这个要注意。



Spring Framework +Mybatis时报SqlSession注册错误 SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6fdbe764] was not registered for synchronization because synchronization is not active Closing non transactional SqlSession [org.apache... 阅读详情

相关推荐

uniapp监听扫码枪键盘事件|无输入框式监听

一般的扫码枪通过USB或蓝牙连接手机或电脑,充当的是一个外接设备。当扫码后,扫码枪会自动识别内容,然后向连接的电脑或手机发送键盘事件keydown或keyup。

tcy9099的专栏 9750

解决Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@38e46e4

解决Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@38e46e4a]异常 1、我自己解决的方法 作为初学者,当我遇到这个异常时也在网上找解决方法,可都没有解决,最后发现是自己操作的问题 我们都运行过sql文件如图 ,如果我们有sql文件,都是右键运行sql文件。 可有时运行时表会跑到系统自带的数据库,如test库,我们不以为然就去我们程序操作,就会报Closing.

LiloveWen的博客 15万+

Calibre电子书阅读器个性化样式定制指南

本文详细介绍了如何通过Calibre电子书阅读器的用户样式表功能进行深度个性化样式定制。从修改全局字体、行距、背景配色(包括深色/浅色模式)到美化代码块、引用等特殊元素,本指南提供了完整的CSS代码示例与实战技巧,帮助用户打造专属的舒适阅读环境,显著提升电子书阅读体验。

vv45678的博客 920

解决Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlS..(22.11.20)

“Closing non transactional SqlSession”,这种情况试一下重新建库建表

qq_48602526的博客 2万+

结构力学程序算法理论基础(一)————虚功原理

1.约束 定义约束:限制质点或者质点系运动的条件称为约束,表示这些限制条件的数学方程称为约束方程。 (1)几何约束 限制质点或者质点系在空间的几何位置的条件称为几何约束.如单摆,其中质点M可绕固定点O在平面Oxy内摆动,摆长为l.这时摆杆对质点的限制条件是:质点M必须在以点O为圆心,以l为半径的圆周上运动.其约束方程为: 又质点M在固定的曲面上运动,那么曲面方程就是质点M的约束方程,即 上...

l93919861的博客 4511

Seedance 2.5本地部署指南:AI生图与视频生成的完整实践

最近在AI生成内容领域,本地部署方案越来越受到开发者关注。特别是Seedance 2.5的发布,让很多原本依赖云端服务的用户开始转向本地化解决方案。本文将从实际使用角度出发,完整介绍Seedance 2.5的本地部署流程、功能特性对比以及实际应用技巧。 1. Seedance 2.5核心特性解析 1.1 什么是Seedance 2.5 Seedance 2.5是一款开源的AI生图和视频生成工具,支持在本地环境运行,无需联网即可实现高质量的图像和视频生成。相比之前的2.0版本,2.5在生成质量、运行效率和功能

weixin_42566121的博客 1674

7.Closing non transactional SqlSession 导致事务失败问题

        博主在研究Spring事务源码,编写测试代码时,出现了Closing non transactional SqlSession 导致事务失败的问题,于是写下这篇文章,记录一下这个问题。 前提         已经通过配置方式...

扛麻袋的少年的博客 5万+

二十一.基于国民MCU 的增加M4F DSP库调用的验证

Cortex-M4F内核不仅内置硬件FPU单元,还支持多种DSP指令集,比如支持单周期乘加指令(MAC)等。因此Cortex-M4执行所有的DSP指令集都可以在单周期内完成,而Cortex-M3和M0需要多个指令和多个周期才能完成同样的功能。比如开方运算,M3和M0只能通过迭代法(标准数学函数库)计算,而M4F直接调用VSQRT指令完成。参考:\Nationstech.N32G45x_Library.1.1.1\Nationstech.N32G45x_Library.1.1.1\projects\n32g4

AIoT深度探索者 | 嵌入式系统架构师 深耕物联网(IoT)与人工智能(AI)融合技术,聚焦​​边缘计算、图像开发、低功耗通信协议​​,致力于智能硬件,关注我获取最新技术文章信息与海量资源~ 934

Closing non transactional SqlSession

在执行sql的时候,出现Closing non transactional SqlSession 找了很长时间才发现是什么原因。 解决方式: 1. 启动类添加注解 @EnableTransactionManagement 2. 方法添加注解 @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) spring的事物传播 propagation = Propagation.R...

yang_zzu的博客 3万+

CATIA V6二次开发——如何利用CaptureToFile截屏

CaptureToFile 今天给大家分享一个很有趣的功能,如何利用CATIA自带的功能输出模型展示图? 先上方法: 方法本身并不难,只需要赋予格式及输出路径即可完成该功能。结果如下: 看到这样一张图片不禁让我陷入了沉思,怎么会这么丑???? 那么如何让这个简单的功能变得有趣,图片变得好看点呢? 第一步:背景换色 第二步:隐藏结构树 ...

WorkMan的博客 2982

【RT-DETR有效改进】计算训练好权重文件对应的FPS、推理每张图片的平均时间(科研必备)

本文给大家带来的改进机制是利用我们训练好的权重文件计算FPS,同时打印每张图片所利用的平均时间,模型大小(以MB为单位),同时支持batch_size功能的选择,对于轻量化模型的读者来说,本文的内容对你一定有帮助,可以清晰帮你展示出模型速度性能的提升以及轻量化的效果(模型大小),对于以提高精度为目的的读者本文也能够帮助大家展示出现阶段的模型速度指标。所以本文的内容是十分有用的机制,对于大家发表论文来说,下面的图片为运行后的效果可以看到,该有的指标均已打印(本文内容为我独家创新,全网无第二份)下面是效果图和文

Snu77的博客 3628

Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSql]三更草堂博客项目,友联接口问题

三更友联页面不显示解决

KinozHao个人博客 6038

YOLOv11【第一章:零基础入门篇·第10节】YOLOv11项目实战:从零搭建检测系统!

🏆 本文收录于专栏 《YOLOv11实战:从入门到深度优化》。本专栏围绕 YOLOv11 的改进、训练、部署与工程优化 展开,系统梳理并复现当前主流的 YOLOv11 实战案例与优化方案,内容目前已覆盖 分类、检测、分割、追踪、关键点、OBB 检测 等多个方向。

**My Coding Family** 5770

通俗易懂讲解MyBatis会话管理基础,帮助新手快速理解并解决‘closing non transactional sqlsession‘问题。

掌握SqlSession的正确使用方式是MyBatis入门的关键。SqlSession是重量级对象,必须及时关闭异常情况下也要确保资源释放框架提供的自动管理功能要合理使用最近我在InsCode(快马)平台上实践这些概念时,发现它的一键部署功能特别方便,可以直接看到代码运行效果,还能实时调试,对新手学习MyBatis很有帮助。平台内置的代码编辑器也很友好,不用配置环境就能开始练习,大大降低了学习门槛。

NightshadeRaven21的博客 817

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4f93bf0a]

如图所示,我的global-config(全局配置)位于confiuration下,这将导致我的全局配置无法正常使用,我们只需通过减少global-config前面的方格便能把父类换掉,换成更上一级的mybatis-plus。解决思路:找到自己的yml文件,看看是不是自己的全局配置相应的代码,位置没有放好,要分好子父区别。问题发生原因:更改原有的注解代码,试用全局配置来测试方法。谁知就开始报错了,问题如上图。这样这个问题就解决了。

2301_78922930的博客 4015

深度学习工具包 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")

mybatis:Creating a new SqlSession Closing non transactional SqlSession

Creating a new SqlSession SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@42607e80] was not registered for synchronization because synchronization is not active JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@56ebc6bb] w.

yzh_1346983557的博客 4万+

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@58d6f367]

具体错误提示

m0_71932548的博客 1197

spring中"Closing non transactional SqlSession"的处理

在我们没有开启事务的时候,如果使用mybatis,我们会在日志中看到如下的内容:"Closing non transactional SqlSession",这种情况说明没有开启Spring的事务管理,因此才会关闭一个非事务的SqlSession。   那么如何开启事务管理呢?最简单的方式就是添加下面两条配置: <bean id="transactionManager"

辛星,前进的路上. 13万+

Creating a new SqlSession 或者 Closing non transactional SqlSession

Creating a new SqlSession SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@126562] was not registered for synchronization because synchronization is not active JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@119285] will not be managed by

zcxbd的博客 2278

MyBatis SqlSession原理梳理

工作中,需要学习一下MyBatis sqlSession的产生过程,翻看了mybatis-spring的源码,阅读了一些mybatis的相关doc,对mybatis sqlSession有了一些认知和理解,这里简单的总结和整理一下。 首先, 通过翻阅源码,我们来整理一下mybatis进行持久化操作时重要的几个类: SqlSessionFactoryBuilder:build方...

FeelTouch Labs 1525

mybatis报错:Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSessi

使用mybatis报错,根据控制台打印日志,得出执行sql语句正确无误,说明sql没问题,查看下一行参数赋值,也没问题,推断出是事务的问 题所在,我的解决方案:在对应的service中添加添加注解:@Transactional ,重新启动,报错解决,amazing的是当我删掉这个注解,重 新启动时,又没有报错,持续amazing中。 其他解决方案点击这里参考 添加注解示例: ...

木泽锐 2万+

Spring整合mybatis中的sqlSession是如何做到线程隔离的?

项目中常常使用mybatis配合spring进行数据库操作,但是我们知道,数据的操作是要求做到线程安全的,而且按照原来的jdbc的使用方式,每次操作完成之后都要将连接关闭,但是实际使用中我们并没有这么干。 更让人疑惑的点是,spring中默认使用单例形式来加载bean,而往往我们也不会改变这种默认,所以,是所有线程共享数据连接? 让我们来看看真相! 自然是要个栗子的: 我...

KHOST的博客 387
上一篇: 自己对于mybatis的association的理解
下一篇: Cannot create PoolableConnectionFactory (Communications link failure due to underlying exception 解决
超越自己看到的
博客等级 码龄12年 28粉丝 168原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值