还是spring事务.我把代码贴出来,麻烦大家帮忙..谢谢!!这个问题搞了一天了.头都大了..搞不好就要被开了啊!!
--------------------sessionFactory-----------------------------------
<bean id = "sessionFactory" class = "com.mofit.framework.util.AnnotationSessionFactoryBeanEx">
<property name = "dataSource">
<ref bean = "dataSource"/>
</property>
--------------------transactionManager-------------------------------------------
<bean id = "transactionManager" class = "org.springframework.transaction.jta.JtaTransactionManager">
</bean>
-------------------------------------------------------------------
<!-- 声明式事务 -->
<bean id = "hibernateTxProxy" class = "org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract = "true" lazy-init = "true">
<property name = "transactionManager">
<ref bean = "transactionManager"/>
</property>
<property name="target">
<ref bean="sessionFactory" />
</property>
<property name = "transactionAttributes">
<props>
<prop key = "find*">PROPAGATION_SUPPORTS,readOnly</prop>
<prop key = "*">PROPAGATION_REQUIRED,-AppException</prop>
<prop key = "*">PROPAGATION_REQUIRED,-SQLDataException</prop>
</props>
</property>
</bean>
<!-- 编程式事务 -->
<bean id = "jdbcTxProxy" class = "org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract = "true" lazy-init = "true">
<property name = "transactionManager">
<ref bean = "transactionManager"/>
</property>
<property name="target">
<ref bean="sessionFactory" />
</property>
<property name = "transactionAttributes">
<props>
<prop key = "find*">PROPAGATION_SUPPORTS,readOnly</prop>
<prop key = "*">PROPAGATION_REQUIRED,-AppException</prop>
<prop key = "*">PROPAGATION_REQUIRED,-SQLDataException</prop>
</props>
</property>
</bean>
-----------------把BPO交给事务----------------------------------------------
<bean id = "budgetorginBPOTM" parent = "hibernateTxProxy">
<property name = "target">
<ref bean = "budgetorginBPO"/>
</property>
</bean>
<bean id = "budgetorginBPOJDBCTM" parent = "jdbcTxProxy">
<property name = "target">
<ref bean = "budgetorginBPO"/>
</property>
</bean>
--------------------编程问答-------------------- 你是什么问题啊? --------------------编程问答-------------------- 神马问题。。 --------------------编程问答-------------------- 事务不回滚啊.!!!!!!!
@Transactional(rollbackFor = SQLDataException.class)
public int saveBudgetvoucherSysccid(T_BUDGETVOUCHER budgetvoucher,T_SYSCCID ccid){
return budgetorginBO.saveBudgetvoucherSysccid(budgetvoucher, ccid);
}
public void tranText(){ try{ saveData1(); saveData2(); catch (AppException e){ e.printStackTrace(); } } //保存数据1 public void saveData1() throws AppExcpetion{ ...... //执行保存数据操作 } //保存数据2 public void saveData2()throws AppException{ /// //保存数据库 }
用spring管理事务
假设saveData2()报错.将异常向上抛出到tranText()方法的catch块进行处理
..这个时候spring的事务会将saveData1()方法回滚么???
如果不会..那请问.怎么做?这个AppException是继续向上抛,,抛到哪一层为止..还是怎么办???
谢谢你们了 --------------------编程问答--------------------
--------------------编程问答-------------------- 你们项目开发真是相当飘逸啊,又是配置文件又是注解的一起来啊
public void tranText(){
try{
saveData1();
saveData2();
catch (AppException e){
e.printStackTrace();
}
} //保存数据1
public void saveData1() throws AppExcpetion{ ...... //执行保存数据操作 }
//保存数据2 public void saveData2()throws AppException{ /// //保存数据库 }
@Transactional(rollbackFor = SQLDataException.class)
public int saveBudgetvoucherSysccid(T_BUDGETVOUCHER budgetvoucher,T_SYSCCID ccid){
return budgetorginBO.saveBudgetvoucherSysccid(budgetvoucher, ccid);
}
@Transactional(rollbackFor = SQLDataException.class)
这是什么意思你知道么? 你指定了出现SQLDataException异常你才回滚啊 --------------------编程问答-------------------- catch (AppException e)把异常catch了怎么回滚? --------------------编程问答--------------------
哥啊...现在程序不会出现AppException.就只有某些情况下会出现SQLDataException...所以那里这样写的 --------------------编程问答--------------------
哥....其实我也是这么想的..但是我不知道的是..如果这里不catch.那么就是要继续把这个异常向上抛..
那抛到哪里为止呢???????
补充:Java , Java EE