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个回答

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

没问题,删除不存在数据不会抛出异常

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问