Spring学习 事务回滚
来源:互联网 发布:java接收安卓上传图片 编辑:程序博客网 时间:2024/05/22 02:17
<span style="font-size:24px;"><bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"><property name="dataSource" ref="dataSource" /></bean><tx:annotation-driven transaction-manager="transactionManager"/><!-- 配置事务管理器 --><bean id="transactionManager"class="org.springframework.jdbc.datasource.<strong>DataSourceTransactionManager</strong>"><property name="dataSource" ref="dataSource" /></bean></span>
<span style="font-size:24px;">//RuntimeException @Transactional(noRollbackFor = RuntimeException.class)//Exception @Transactional(rollbackFor = Exception.class)public void deleteUser(String id) {String sqlStr = "delete from t_user where user_id = ? ";jdbcTemplate.update(sqlStr, new Object[] { id });throw new RuntimeException("----运行期异常----");}</span>
结论:默认情况下,unchecked exception是会回滚的。checked exception不会回滚。当然可以通过配置文件爱你进行修改。如上面的注释部分。
<strong style="background-color: rgb(102, 255, 255);">@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true,timeout=3000)</strong>@SuppressWarnings("deprecation")public int getMatchCount(String userName, String password) {String sqlStr = "SELECT count(*) FROM t_user WHERE user_name=? and password=?";return jdbcTemplate.queryForInt(sqlStr, new Object[] { userName,password });}
事务的传播行为 有7种,Propagation.xxxxx . 如 RQUIRED/NO_SUPPORTED/NEVER/REQUIRED_NEW/MANDATORY/SUPPORTS/NESTED.
其中NESTED是Spring特有的。有保存点的说法。内部出错,对外部嵌套的没影响。但外部出错了,内部就要回滚的
0 0
- Spring学习 事务回滚
- Spring事务回滚
- spring事务回滚
- spring事务回滚
- spring事务回滚
- spring回滚事务
- spring 事务回滚
- spring 事务回滚
- spring事务回滚
- Spring事务回滚
- [Spring]事务回滚
- Spring事务回滚
- spring事务回滚
- 强制回滚spring事务
- Spring 事务无法回滚
- spring事务的回滚
- spring 事务没有回滚
- spring手动回滚事务
- python拷贝文件夹中特定日期内的文件
- 训练--最短路--01
- SQLSERVER中根据字符截取字符串
- mysql_connect()“No such file or directory”错误排除
- ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA...
- Spring学习 事务回滚
- hdu 5011 Game 博弈
- CSRF攻击2
- 深入理解java多态性
- Volley 设置setRetryPolicy中Retry 为0后 还出现重复连接的问题
- PCB分层及堆叠
- Android 和 ios都能够和javascript交互了!!!
- <IMG>标签的方方面面
- 正则:正则表达式在js中的高级应用