--------------------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);
}
假设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{ /// //保存数据库 }
public int saveBudgetvoucherSysccid(T_BUDGETVOUCHER budgetvoucher,T_SYSCCID ccid){
return budgetorginBO.saveBudgetvoucherSysccid(budgetvoucher, ccid);
}@Transactional(rollbackFor = SQLDataException.class)
这是什么意思你知道么? 你指定了出现SQLDataException异常你才回滚啊
哥啊...现在程序不会出现AppException.就只有某些情况下会出现SQLDataException...所以那里这样写的
那抛到哪里为止呢???????