public boolean insertTxTest() {
try {// 添加异常捕获 事务不能回滚 name 是主键,不添加异常捕获 事务正常回滚。
UserBean userBean = new UserBean();
userBean.setName("张三");
userBean.setPw("123456");
getSqlMapClientTemplate().insert("tx.insert",userBean);
getSqlMapClientTemplate().insert("tx.insert",userBean);
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
<!-- 事务处理器 -->
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>txTestDao</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean>
现在问题是怎么在添加 异常捕获 情况下 事务也正常回滚。
谢谢
解决方案 »
- java.sql.SQLException: Invalid value for getInt() - 'XB2009031100002'
- hibernate使用save 后rollback不起作用
- JSF中commandButton的action和 JS 执行顺序
- weblogic上部署项目(struts+hibernate)
- firefox 里为什么getElementById不支持,
- 请教jsp和servlet之间值的传递问题
- J2EE网站经验共享!
- Status 安装在tomcat 中运行为什么会报以下问题???
- 在Java中调用C#.net写的Web Service,返回值都是null,错在哪?
- ejb的客户端测试,为什么说找不到WEBLOGIC服务器
- poi 生成文件名乱码问题 求大神 求解
- (请高手)为什么我在用mian的时候,能获取值,但是用servlet的时候为空
boolean result=false;
try{
result=insertTxTest();
}catch (Exception e) {
e.printStackTrace();
}