spring事务.我把代码贴出来,麻烦大家帮忙..谢谢!!这个问题搞了一天了.头都大了..搞不好就要被开了啊!!

easonwang 发布于 2011/12/06 11:14
阅读 474
收藏 0
--------------------sessionFactory----------------------------------- 
<bean id = "sessionFactory" class = "com.mofit.framework.util.AnnotationSessionFactoryBeanEx"> 
    <property name = "dataSource"> 
        <ref bean = "dataSource"/> 
    </property> </bean> 
--------------------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); 
} 

加载中
0
鉴客
鉴客
问题是什么?
easonwang
easonwang
它就是出现异常之后.不回滚 不好意思啊..忘了把问题说出来
0
easonwang
easonwang
    public void tranText(){ 
        try{ 
            saveData1(); 
            saveData2(); 
        }catch (AppException e){ 
            e.printStackTrace(); 
        } 
} 
//保存数据1 
public void saveData1() throws AppExcpetion{ 
    ...... //执行保存数据操作 
}
 //保存数据2 
public void saveData2()throws AppException{ 
    /// //保存数据库
}
就是现在saveData2()方法报错了saveData1()不会回滚

0
黄平俊
黄平俊
查看一下是不是异常捕捉不正确~~ AppException 和 rollbackFor = SQLDataException. class
easonwang
easonwang
AppException 我自己测试的时候是不会报的..但是他们写的都从下面抛出来了..所以我这里必须要接收 SQLDATAException.会在执行SQL的时候报出来啊..
0
cwledit
cwledit
使用的应用服务器是什么?
easonwang
easonwang
weblogic
0
cwledit
cwledit
给 <bean id = "transactionManager" class = "org.springframework.transaction.jta.JtaTransactionManager">

 </bean>

加个属性:  <property name="transactionManagerName">
                         <value>javax.transaction.TransactionManager</value>
                </property>

easonwang
easonwang
额...谢谢你...不过..还是不行
0
cwledit
cwledit
TransactionProxyFactoryBean 实在不是很熟悉, 这个都快被淘汰了吧, 为什么不使用新的事务配置试试呢?
easonwang
easonwang
没有...用的c3p0连接池
cwledit
cwledit
@easonwang : 你的datasource是通过JNDI获得的吗?
easonwang
easonwang
请问一下.新的事务配置是什么啊? 我们现在做的这整个系统就是用的那个鸟东西..估计要再换也不太可能
返回顶部
顶部