xushiwei003 2010-09-04 19:49
浏览 553
已采纳

SSH 中 atomikos集成JTA 事务无法回滚

applicationContext.xml配置文件如下

<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
init-method="init" destroy-method="close">
oracle xa datasource

oracle1


oracle.jdbc.xa.client.OracleXADataSource



test
test
jdbc:oracle:thin:@192.168.0.28:1521:test


<bean id="dataSourceOracle"
    class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init"
    destroy-method="close">
    <property name="uniqueResourceName">
        <value>oracle2</value>
    </property>
    <property name="xaDataSourceClassName">
        <value>oracle.jdbc.xa.client.OracleXADataSource</value>
    </property>
    <property name="xaProperties">
        <props>
            <prop key="user">test1</prop>
            <prop key="password">test1</prop>
            <prop key="URL">jdbc:oracle:thin:@192.168.0.28:1521:test</prop>
        </props>
    </property>
</bean>

<bean id="sessionFactory1"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
        <ref bean="dataSource" />
    </property>

    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">
                org.hibernate.dialect.Oracle9Dialect
            </prop>
            <prop key="hibernate .show_sql">true</prop>
            <prop key="hibernate.max_fetch_depth">1</prop>
            <prop key="hibernate.jdbc.fetch_size">20</prop>
            <prop key="hibernate.query.factory_class">
                org.hibernate.hql.ast.ASTQueryTranslatorFactory
            </prop>
        </props>
    </property>
    <property name="jtaTransactionManager"
        ref="atomikosTransactionManager" />
    <property name="mappingDirectoryLocations">
        <list>
            <value>
                classpath*:com/yappam/model/
            </value>
        </list>
    </property>
</bean>
<bean id="sessionFactory2"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
        <ref bean="dataSourceOracle" />
    </property>
    <property name="hibernateProperties">
        <props>[b][/b]
            <prop key="hibernate.dialect">
                org.hibernate.dialect.Oracle9Dialect
            </prop>
            <prop key="hibernate .show_sql">true</prop>
            <prop key="hibernate.max_fetch_depth">1</prop>
            <prop key="hibernate.jdbc.fetch_size">20</prop>
            <prop key="hibernate.query.factory_class">
                org.hibernate.hql.ast.ASTQueryTranslatorFactory
            </prop>
        </props>
    </property>
    <property name="jtaTransactionManager"
        ref="atomikosTransactionManager" />
    <property name="mappingLocations">
        <list>
            <value>
                classpath*:com/yappam/model/oracle/*.hbm.xml
            </value>
        </list>
    </property>
</bean>

<bean id="atomikosTransactionManager"
    class="com.atomikos.icatch.jta.UserTransactionManager"
    init-method="init" destroy-method="close">
    <property name="forceShutdown">
        <value>true</value>
    </property>
</bean>
<bean id="txManager"
    class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="userTransaction" ref="atomikosUserTransaction" />
    <property name="transactionManager"
        ref="atomikosTransactionManager">
    </property>
</bean>

<bean id="atomikosUserTransaction"
    class="com.atomikos.icatch.jta.UserTransactionImp">
    <property name="transactionTimeout">
        <value>240</value>
    </property>
</bean>


<tx:advice id="txAdvice" transaction-manager="txManager">
    <tx:attributes>
        <tx:method name="save*" propagation="REQUIRED"
            rollback-for="Exception" />
        <tx:method name="delete*" propagation="REQUIRED"
            rollback-for="Exception" />
        <tx:method name="update*" propagation="REQUIRED"
            rollback-for="Exception" />
        <tx:method name="*"  propagation="REQUIRED" />
    </tx:attributes>
</tx:advice>

<aop:config proxy-target-class="true">
    <aop:pointcut id="iPointCuts"
        expression="execution(* com.yappam.service.impl..*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="iPointCuts" />
</aop:config>

如果将事务的隔离界别设置成 read-only="true",则两个数据库都才、不能插入数据,
但是我现在
User user=new User();
user.setId("0000000000128359568004600001372");//不存在数据
userDao.delete(user);

    Test t=new Test();
    t.setId(IDGenerator.getId());
    t.setUsername("222");
    testDao.save(t);

我先删除一条不存在信息抛出异常,但是事务却不回滚,任然可以有一个数据库插入成功?

请大家帮忙解决下!谢谢

  • 写回答

2条回答 默认 最新

  • lizhiyezi 2010-09-04 19:52
    关注

    抛出RuntimeException异常。或者配置事物处理异常

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵