applicationContext.xml配置文件如下<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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">
<bean id="dataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
init-method="init" destroy-method="close">
<description>oracle xa datasource</description>
<property name="uniqueResourceName">
<value>oracle1</value>
</property>
<property name="xaDataSourceClassName">
<value>oracle.jdbc.xa.client.OracleXADataSource</value>
</property>
<property name="xaProperties">
<props>
<prop key="user">test</prop>
<prop key="password">test</prop>
<prop key="URL">jdbc:oracle:thin:@192.168.0.28:1521:test</prop>
</props>
</property>
</bean>

<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>
<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>
</beans>如果将事务的隔离界别设置成 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);
我先删除一条不存在信息抛出异常,但是事务却不回滚,任然可以有一个数据库插入成功?请大家帮忙解决下!谢谢

解决方案 »

  1.   

    补充下:   public void delete(Object entity) {
    this.getHibernateTemplate().delete(entity);

    }这个方法是我的删除方法,这个类我是继承HibernateDaoSupport类,但是我用上atomikos集成JTA 事务后如果删除不存在的信息他不会抛出任何异常,但是也执行了,谁知道这是什么原因啊,愁了一天了。
      

  2.   

    怎么没人啊,对于回滚我手动抛出RuntimeException异常可以回滚,但是现在我执行
    public void delete(Object entity) {
    this.getHibernateTemplate().delete(entity);}删除方法时,当数据库中不存在记录删除失败时不抛出任何异常,不知道为什么?