事物作用的impl类这样写的

@Override
public int updateReturnAll(int item, int status, int idUser) {
// TODO Auto-generated method stub
try {
int updateReturnAll = itemMapper.update****();
if(updateReturnAll>0){
Map<String, Object> map=new HashMap<String,Object>();
map.put("idpatient", item);
map.put("ChargeDealWith", 0);
Object callUpdatePPFIReturn = itemMapper.callUpdate****(map);
System.out.println(callUpdatePPFIReturn+"==================");
System.out.println(map.get("RetMeg")+"----------");
if(!map.get("RetMeg").equals("")){
throw new Exception("callUpdatePPFIReturn异常!");
}
return updateReturnAll;
}else{
return 0;
} } catch (Exception e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
logger.error("updateReturnAll异常!",e);
return 0;
}
}

如果没有

TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();指定异常回滚,update是会提交的
此时,为了防止提交,是需要将异常抛出的,以便让aop捕获异常再去回滚
@官网文档
1.4.3. Rolling Back a Declarative Transaction
The previous section outlined the basics of how to specify transactional settings for classes, typically service layer classes, declaratively in your application. This section describes how you can control the rollback of transactions in a simple, declarative fashion. The recommended way to indicate to the Spring Framework’s transaction infrastructure that a transaction’s work is to be rolled back is to throw an Exception from code that is currently executing in the context of a transaction. The Spring Framework’s transaction infrastructure code catches any unhandled Exception as it bubbles up the call stack and makes a determination whether to mark the transaction for rollback. In its default configuration, the Spring Framework’s transaction infrastructure code marks a transaction for rollback only in the case of runtime, unchecked exceptions. That is, when the thrown exception is an instance or subclass of RuntimeException. ( Error instances also, by default, result in a rollback). Checked exceptions that are thrown from a transactional method do not result in rollback in the default configuration. You can configure exactly which Exception types mark a transaction for rollback, including checked exceptions. The following XML snippet demonstrates how you configure rollback for a checked, application-specific Exception type: <tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" rollback-for="NoProductInStockException"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
If you do not want a transaction rolled back when an exception is thrown, you can also specify 'no rollback rules'. The following example tells the Spring Framework’s transaction infrastructure to commit the attendant transaction even in the face of an unhandled InstrumentNotFoundException: <tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="updateStock" no-rollback-for="InstrumentNotFoundException"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
When the Spring Framework’s transaction infrastructure catches an exception and it consults the configured rollback rules to determine whether to mark the transaction for rollback, the strongest matching rule wins. So, in the case of the following configuration, any exception other than an InstrumentNotFoundException results in a rollback of the attendant transaction: <tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="*" rollback-for="Throwable" no-rollback-for="InstrumentNotFoundException"/>
</tx:attributes>
</tx:advice>
You can also indicate a required rollback programmatically. Although simple, this process is quite invasive and tightly couples your code to the Spring Framework’s transaction infrastructure. The following example shows how to programmatically indicate a required rollback: public void resolvePosition() {
try {
// some business logic...
} catch (NoProductInStockException ex) {
// trigger rollback programmatically
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
}
}
You are strongly encouraged to use the declarative approach to rollback, if at all possible. Programmatic rollback is available should you absolutely need it, but its usage flies in the face of achieving a clean POJO-based architecture.

												

springmvc+mybaits一个事物同时update和调用存储过程异常回滚的更多相关文章

  1. nestd事务如果报错了 则回滚到外部事物保存点 且外部事物如果没异常的话 会正常提交 nested事务并不会提交;如果外部事物报错了 内部事务会一同回滚

    nestd事务如果报错了 则回滚到外部事物保存点 且外部事物如果没异常的话 会正常提交 nested事务并不会提交:如果外部事物报错了 内部事务会一同回滚

  2. spring事物回滚机制 (事务异常回滚,捕获异常不抛出就不会回滚)

    当异常被捕获catch的时候,spring的事物则不会回滚 为什么不会滚呢??  spring aop  异常捕获原理:被拦截的方法需显式抛出异常,并不能经任何处理,这样aop代理才能捕获到方法的异常 ...

  3. asp.net调用存储过程详解

    摘要 存储过程的调用在B/S系统中用的很多.传统的调用方法不仅速度慢,而且代码会随着存储过程的增多不断膨胀,难以维护.新的方法在一定程度上解决了这些问题. 关键词 ASP.NET:存储过程   在使用 ...

  4. PL/Sql 中创建、调试、调用存储过程

    存储过程的详细建立方法 1.先建存储过程 左边的浏览窗口选择 procedures ,会列出所有的存储过程,右击文件夹procedures单击菜单"new",弹出 template ...

  5. java陷阱之spring事物未提交和回滚导致不可预知问题

    案发现场 //防止全局配置了 所以这里定义sprnig 不托管事物 @Transactional(propagation = Propagation.NOT_SUPPORTED) public boo ...

  6. springboot事物回滚

    要添加事物 必须在方法上添加 @Transactional 注解 如果需要事物回滚有两个条件 1.方法中有异常或者主动抛异常 2.主动去回滚 TransactionAspectSupport.curr ...

  7. django事物回滚

    往数据库写入数据时,不经意间就会写入不完整的数据,我们称之为脏数据.事务管理(transaction)可以防止这种情况发生.事务管理一旦检测到写入异常,会执行回滚操作,即要么写入完整的数据,要么不写入 ...

  8. @Transactional-同一个类中方法自调,调用方法事物失效

    问题分析 一个类中的方法调用另一个事物传播性为创建事物的方法,调用的方法事物失效? SpringAOP 代理的Service对象调用了其方法,这个方法再去调用这个Service中的其他方法是没有使用A ...

  9. hibernate的update() 更新延迟或者无法更新,导致同个service调用存储过程执行方法不精确

    hibernate的update()方法无法更新,不报错 原因是hibernate的update方法操作的是缓存,可以flush下先. 设置缓存为false理论上也可. 在一个serivce方法里,执 ...

随机推荐

  1. cool 软件 —— Carnac(实时桌面显示按键)

    1. Carnac 下载地址:Carnac, the Magnificent Keyboard Utility 使用说明:carnac – 在屏幕实时显示按键操作

  2. Linux 定制X86平台操作系统

    /********************************************************************************* * Linux 定制X86平台操作 ...

  3. 2018c语言第2次作业

    1 删除字符串中数字字符 1.设计思路 (1)主要描述题目算法 第一步:先用for循环比较每个数是否符合删除条件. 第二步:如果符合就把这个数利用交换把这个数提前一位. 2.实验代码 void del ...

  4. JPA中的Page与Pageable

    Page是Spring Data提供的一个接口,该接口表示一部分数据的集合以及其相关的下一部分数据.数据总数等相关信息,通过该接口,我们可以得到数据的总体信息(数据总数.总页数...)以及当前数据的信 ...

  5. 替换国内yum源以及pip源

    因为一些原因,不论是网络还是啥啥啥的原因,国外的源访问时不时的很慢,这时候我们就可以将国外的源替换为国内源,提高下载速度. yum源替换 环境:centos7(如果你的发行版本不是这个,此方法不保证能 ...

  6. 转 GraphQL Schema Stitching explained: Schema Delegation

    转自官方文档 In the last article, we discussed the ins and outs of remote (executable) schemas. These remo ...

  7. android高速上手(三)经常使用控件使用

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/wangpeifeng669/article/details/26288387 完毕了android的 ...

  8. oracle计算两个日期的时间差时分秒

    Oracle函数可以实现诸多的功能,下面就介绍使用oracle函数计算时间差的实现方法. 两个Date类型字段:START_DATE,END_DATE,计算这两个日期的时间差(分别以天,小时,分钟,秒 ...

  9. hadoop之 安全模式及SafeModeException

    问题: hadoop启动的时候报错 HTTP ERROR 500 Problem accessing /nn_browsedfscontent.jsp. Reason: Cannot issue de ...

  10. centos7 安装配置rsyslog + LogAnalyzer + mysql

    https://www.cnblogs.com/mchina/p/linux-centos-rsyslog-loganalyzer-mysql-log-server.html 安装LNMP 一键安装包 ...