“Transaction rolled back because it has been marked as rollback-only”

 

spring的声明事务提供了强大功能,让我们把业务关注和非业务关注的东西又分离开了。好东西的使用,总是需要有代价的。使用声明事务的时候,一个不小心经常会碰到“Transaction rolled back because it has been marked as rollback-only”这个异常。有时候又常常会纳闷,"我已经try-catch了,为什么还这样呢?"

 

	<!-- 0 placeHolder -->
	<bean  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>files/pro.properties</value>
			</list>
		</property>
	</bean>
	
	<!-- 1 dataSource -->
	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
		<property name="url" value="${jdbc.mysql.url}"></property>
		<property name="username" value="${jdbc.username}"></property>
		<property name="password" value="${jdbc.userpassword}"></property>
	</bean>
	
	<!-- 2 jdbcTemplate -->
	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource" ref="dataSource"></property>
	</bean>
	
	<!-- 3 BaseDao -->
	<bean id="baseDao" class="transaction.dao.BaseDao" abstract="true">
		<property name="jdbcTemplate" ref="jdbcTemplate" />
	</bean>
	
	<bean id="aDao" class="transaction.dao.Adao" parent="baseDao">
	</bean>
	
	<bean id="bDao" class="transaction.dao.Bdao" parent="baseDao"> 
	</bean>
	
	<!-- 4 service -->
	<bean id="aBo" class="transaction.bo.AboImpl">
		<property name="aDao" ref="aDao" />
		<property name="bBo" ref="bBo" />
	</bean>
	
	<bean id="bBo" class="transaction.bo.BboImpl">
		<property name="bDao" ref="bDao" />
	</bean>
	
	<!-- 5 transaction -->
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	
	<bean id="transactionInterceptor1" class="org.springframework.transaction.interceptor.TransactionInterceptor" >
		<property name="transactionManager" ref="transactionManager"></property>
		<property name="transactionAttributes">
			<props>
				<prop key="*">PROPAGATION_REQUIRED</prop>
			</props>	
		</property>
	</bean>
	
	<bean id="autoProxy1"  class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<property name="beanNames">
			<list>
				<value>*Bo</value>
			</list>
		</property>
		<property name="interceptorNames">
			<list>
			<!--  
				<value>transactionInterceptor2</value>
				-->
				<value>transactionInterceptor1</value>	
			</list>
		</property>
	</bean>

 这里的声明事务是作用于所有以Bo为后缀的bean的所有方法上,使用REQUIRED传播方式。

	public int insertA(A a) 
	{
		aDao.insertA(a);
		
		B b = new B();
		b.setName("bbb");
		try
		{
			bBo.insertB(b);
		}
		catch(Exception e)
		{
			System.out.println("aaa");
		}
		return 0;
	}

 这里,insertA 开始一个事务,调用aDao.insertA(a)[一个简单的数据库操作],然后调用 bBo.insertB(b)[bo调dao,dao直接抛异常]。bBo的insertB方法,也要开始一个事务,但是这里的传播机制是REQUIRED。OK,和insertA 的事务合二为一吧。因为bBo.insertB(b)会抛异常出来,这里try-catch下,希望aDao.insertA(a)的操作能够成功。

但是现实总是残酷的,这里会有一个大大的 “Transaction rolled back because it has been marked as rollback-only” ,结果你会发现aDao.insertA(a)的操作也没有成功。

 

try-catch不起作用的原因简单的说就是,try-catch的不是地方,你认为你的try-catch是最接近异常抛出点了,是第一个处理的handler了。实际上,spring在更早一步就try-catch 住了,同时还设置了一些标志位,再把catch住的异常往外抛。这个时候才是我们的try-catch。而"Transaction rolled back because it has been marked as rollback-only"就是因为事务在提交的时候,发现标志位已经被设置了,不应该去提交了,然后吭哧吭哧的回滚调,再提示你已经被设置成rollback-only了。

 

原因是既然如此,那么在不改变代码的情况下,依靠配置能否解决这个问题呢?使用PROPAGATION_REQUIRES_NEW吧。对于bBo.insertB(b)开个新的事务,如果失败了就回滚调,不影响外面的insertA不就OK了。最简单的情况就是在transactionInterceptor1前面,再加个拦截器transactionInterceptor2,该拦截器只针对insertB的事务属性进行修改。

	<bean id="autoProxy1"  class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<property name="beanNames">
			<list>
				<value>*Bo</value>
			</list>
		</property>
		<property name="interceptorNames">
			<list>
			 
				<value>transactionInterceptor2</value>
				
				<value>transactionInterceptor1</value>	
			</list>
		</property>
	</bean>
	
	
	<bean id="transactionInterceptor2" class="org.springframework.transaction.interceptor.TransactionInterceptor" >
		<property name="transactionManager" ref="transactionManager"></property>
		<property name="transactionAttributes">
			<props>
				<prop key="insertB">PROPAGATION_REQUIRES_NEW</prop>
			</props>	
		</property>
	</bean>

注意interceptorNames里面元素的位置。先要使用transactionInterceptor2,再使用transactionInterceptor1.因为调用insertB的时候,transactionInterceptor2先开了一个新事务,而后transactionInterceptor1融合进这个事务。如果这2个拦截器的顺序颠倒的话,那么还是会出现“Transaction rolled back because it has been marked as rollback-only”。因为,transactionInterceptor2生成事务回滚以后,还是会把ex抛给transactionInterceptor1。这个时候,transactionInterceptor1的事务和insertA的事务是同一个。transactionInterceptor1,把标志设置好,等到insertA真的结束的时候,因为异常被我们的try-catch捕获了,spring就会发现需要提交的事务具有一个已经被标记号的rollback。所以就又抛出来了。

 

但是如果系统有很多遗留的因素导致你不敢盲目的修改配置文件的话(比如事务的poincut),那么我们就再加一个事务proxy就OK了。

<bean id="autoProxy2" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<property name="beanNames">
			<list>
				<value>*Bo</value>
			</list>
		</property>
		<property name="interceptorNames">
			<list>
				<value>transactionInterceptor2</value>
				<!--  
				<value>transactionInterceptor1</value>	
			    -->
			</list>
		</property>
	</bean>
	
	<bean id="autoProxy1"  class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<property name="beanNames">
			<list>
				<value>*Bo</value>
			</list>
		</property>
		<property name="interceptorNames">
			<list>
			<value>transactionInterceptor1</value>	
			<!--  
			<value>transactionInterceptor2</value>		
			-->		
			</list>
		</property>
	</bean>

如上的配置还是会带来悲剧的“Transaction rolled back because it has been marked as rollback-only”。

 

但是如果我们把 autoProxy2 放到 autoProxy1 或者给自动代理加上顺序的话。。。结果就是喜剧了。。

<bean id="autoProxy1"  class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<property name="beanNames">
			<list>
				<value>*Bo</value>
			</list>
		</property>
		<property name="interceptorNames">
			<list>
			<value>transactionInterceptor1</value>	
			<!--  
			<value>transactionInterceptor2</value>		
			-->		
			</list>
		</property>
	</bean>
	
	
	<bean id="autoProxy2" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<property name="beanNames">
			<list>
				<value>*Bo</value>
			</list>
		</property>
		<property name="interceptorNames">
			<list>
				<value>transactionInterceptor2</value>
				<!--  
				<value>transactionInterceptor1</value>	
			    -->
			</list>
		</property>
	</bean>

 

 

造成这个原因是由使用了2个代理的顺序导致的。

在做自动代理的时候,spring会按照postBeanProcessor bean声明的顺序(如果没有设置顺序的话),来依次处理bean。如果autoProxy2 在 autoProxy1 之前,这样transactionInterceptor2 就会更加贴近insertB的调用,其效果就像

<bean id="autoProxy1"  class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<property name="beanNames">
			<list>
				<value>*Bo</value>
			</list>
		</property>
		<property name="interceptorNames">
			<list>
			<value>transactionInterceptor1</value>	
		 
			<value>transactionInterceptor2</value>		
				
			</list>
		</property>
	</bean>

 的配置。

 

 

看来~~~ spring 还是要注意bean的顺序啊,哈哈哈。。。

Transaction rolled back because it has been marked as rollback-only 阅读详情

相关推荐

出现 Transaction rolled back because it has been marked as rollback-only 解决方法

出现 Transaction rolled back because it has been marked as rollback-only 解决方法

码农研究僧的博客 1万+

spring 事务问题:Transaction rolled back because it has been marked as rollback-only

问题描述: 同事测试时使用异常数据,代码报错但是并不是异常产生的错误,而出现: Transaction rolled back because it has been marked as rollback-only 中文翻译就是: 事务已回滚,因为它被标记成了只回滚 代码片段: // 我的代码 @Transactional(readOnly = true, rollbackFor = Exception.class) public String select(Stri

sunayn的博客 2万+

别再买模块了!手把手教你用FT232RL-REEL芯片,从零设计一个USB转串口电路板

本文详细介绍了如何使用FT232RL-REEL芯片从零设计USB转串口电路板,涵盖核心器件选型、原理图设计、PCB布局布线及焊接调试等关键步骤。通过实战案例和性能对比,展示自制电路板在成本、性能和可靠性上的优势,特别适合硬件爱好者和工程师参考。

weixin_30561425的博客 439

Transaction rolled back because it has been marked as rollback-only”

spring的声明事务提供了强大功能,让我们把业务关注和非业务关注的东西又分离开了。好东西的使用,总是需要有代价的。使用声明事务的时候,一个不小心经常会碰到“Transaction rolled back because it has been marked as rollback-only”这个异常。有时候又常常会纳闷,"我已经try-catch了,为什么还这样呢?" Xml代码  1.&lt;...

lilin520530的专栏 198

MRST开源油藏模拟:从入门到精通的全流程指南

本文全面介绍了MRST开源油藏模拟工具的使用方法,从环境搭建到核心功能实战,再到性能优化和工业级应用。MRST作为一款基于MATLAB的开源工具,为油藏工程师提供了强大的数值模拟能力,特别适合教学和科研场景。文章还分享了二次开发技巧和常见问题解决方案,帮助读者快速掌握油藏模拟技术。

beer8的博客 338

Waymo数据集里的隐藏彩蛋:5个激光雷达数据融合实战(附Python代码)

本文深入解析Waymo数据集中5个激光雷达的数据融合技术,提供Python实战代码,帮助开发者掌握多传感器协同工作的关键方法。通过时间同步、坐标转换和运动补偿等技术,实现高精度3D场景重建,提升自动驾驶系统的环境感知能力。

weixin_30399821的博客 87

try catch使用导致出现“Transaction rolled back because it has been marked as rollback-only”问题解决

最近公司的一个项目上线,测试、准生产环境测试都正常,但是生产测试当天就出现了**“Transaction rolled back because it has been marked as rollback-only”** 代码逻辑很简单: try{ 方法B }catch(Exception e){ //异常打印 } 方法B就是为了去获取与第三方交互的公钥,先取本地缓存,无缓存就取数据库。 就是这里!! 运维人员只是清除了缓存中value并没有把key删除,导致方法B代码逻辑出现空指针异常(自己菜,没有做

jianghao19930505的博客 1609

TMS320C6678开发笔记1-6---C6678单核烧写程序

第6节 单核烧写加载程序 6.1节 TI参考文档 参考文档:《KeystoneI Bootloader Resources and FAQ》讲的非常好,建议一定要看 https://processors.wiki.ti.com/index.php/KeystoneI_Bootloader_Resources_and_FAQ#Direct_Boot_Examples_.28without_IBL.29 里面有三个工程: C6678 EVM SPI boot example C6657 EVM ..

kunkliu的博客 5712

Spring事务中“Transaction rolled back because it has been marked as rollback-only“异常是如何产生的

摘要:Spring事务中"Transaction rolled back because it has been marked as rollback-only"异常通常发生在内部方法抛出RuntimeException并被捕获时。关键原因是Spring在检测到未检查异常后会立即将事务标记为rollback-only,即使后续捕获了异常,这个标记也无法撤销。解决方案是使用@Transactional(propagation=REQUIRES_NEW)为内部方法创建独立事务,使其异常不影响

huing的博客 477

从零到一:Quartus II连接开发板实战,打通绘图、管脚分配、编译与下载全链路

本文详细介绍了使用Quartus II软件连接FPGA开发板并完成首个项目的全流程。从硬件连接到驱动安装,到绘制电路框图、精准分配管脚,再到编译设置与最终下载,手把手指导您打通从设计到硬件实现的完整链路,是FPGA初学者的实战入门指南。

mqtt6iot的博客 722

Python爬虫实战:用BeautifulSoup和Pandas轻松抓取去哪儿网景点数据(附完整代码)

本文详细介绍了如何使用Python的BeautifulSoup和Pandas库构建一个高效的旅游数据爬虫,从去哪儿网抓取景点数据。内容涵盖环境准备、网页结构分析、核心代码实现、反爬策略以及数据清洗与存储,提供完整代码示例,帮助开发者快速掌握数据采集技术。

river的博客 362

Java报错Transaction rolled back because it has been marked as rollback-only

当外层方法(如 ServiceA.methodA())和内层方法(如 ServiceB.methodB())都开启了事务,且使用默认的事务传播行为 REQUIRED(即加入当前事务,若没有则新建),两者会共享同一个事务。外层方法 methodA() 捕获了异常(或未处理异常),并尝试提交事务,但此时事务已被标记为 rollback-only,Spring 会强制回滚并抛出此错误。标记回滚:内层事务抛出异常后,事务被标记为 rollback-only,外层事务无法覆盖此标记。// 独立事务,回滚不影响外层。

weixin_43203976的博客 2007

基于STM32的蓝牙智能药盒设计

本研究设计了一种基于STM32F103C8T6单片机的蓝牙智能药盒系统,针对老年人用药管理需求,集成了定时提醒、药量检测、环境监测等功能。系统通过LCD1602显示屏实时显示时间与用药信息,支持每日3次定时提醒及3种药物用量设置,采用DHT11温湿度传感器、HX711药量检测模块和红外传感器实现环境监控,并通过蓝牙模块实现远程用药提醒。测试结果表明,系统定时误差≤30秒,温湿度监测精度±2℃,药量检测误差<1g,各项功能运行稳定。该设计为解决老年人用药依从性问题提供了智能化解决方案,具有实用价值和应用前景。

3254968421的博客 551

关于“Transaction rolled back because it has been marked as rollback-only”报错的记录

于是去仔细看spring事务注意事项,偶然看到spring事务的回滚,是不受try-catch限制,只要发生了异常,当前事务就会标记为回滚,再结合我看到的一条本地日志,发现是方法A调用的另一个service类的方法C产生了插入异常,只不过被方法C自己try-catch处理了,这样方法A在同一个事务下没有正常回滚,就会报错。debug代码,检查报错的位置,但是很多次都没有发现报错位置,又开始检查事务嵌套的问题,因为这段代码是有同一个service的两个事务方法互相调用,属于方法A调用方法B。

qq_60671179的博客 310

对CryptoDriver里密钥格式定义的探索(1)

一入网络安全才发现深似海,传统汽车MCU码农转型之路异常艰难。在CP AUTOSAR中的CryptoDriver SWS对密钥格式的需求来源于RFC,其中要求了RSA、ECC、SHE等key material的格式。再往下看,我就有些迷糊了,例如关于RSA Private Key的OCTEE STRING格式根据IETF RFC8017,Public Key又得根据RFC5280,完全不得其解。所以今天先从生成密钥对,并对其进行解析开始,一步一步拆解。

认真搞搞汽车MCU 534

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

Transaction rolled back because it has been marked as rollback-only问题解决

除了NESTED外还有REQUIRES_NEW这个级别,它是新建一个新的事务,和NESTED的区别就是,REQUIRES_NEW是两个事务,同级,A跟B各自创建了一个事务,NESTED是父子级,B的事务在A里面。如果使用了这个级别,那么testB()会嵌套在testA()里,遇到异常时会回滚到开始执行testB()的数据,将原来的整体事务回滚修改为局部事务回滚,这样的话在testA()捕获了异常以后也不会影响testA()的其他业务执行。业务A是外层业务,调用了业务B内层业务。并且try-catch了它。

qq_36008278的博客 1112

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Transaction rolled back because it has been marked as rollback-only 解决办法

       今天早上高高兴兴上班,居然收到一大堆报警信息,仔细看了一下具体内容,都在提示这个错误 :"Transaction rolled back because it has been marked as rollback-only" 我一看就觉得奇怪了,为什么会有rollback呢,出现问题的地方,就是一个get查询,而且已经标记为readonly=true了。 下面是项目的事务配置...

huangweijian93的博客 4万+

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

报错:Transaction rolled back because it has been marked as rollback-only

报错:Transaction rolled back because it has been marked as rollback-only 原因:使用heibernate查询实体时,没在实体和数据库中添加属性字段(期间估计一般人不会出这种错误,粗心造成的)

weixin_42620858的博客 788
上一篇: 做数据迁移,升级,初始化时需要注意的事情
下一篇: 从一个死锁看mysql innodb的锁机制
wind_sunshine
博客等级 码龄21年 0粉丝 1原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值