同意老大,但是不是传播特性REQUEST_NEW这个是不是应该这么写REQUIRED_NEW ?不知道LZ看懂了么,给 B 指定事务传播为REQUIRED_NEW,不管别人怎么开事务,他自己会再新开一个,这样就不会受别的事务的影响了
<?xml version="1.0" encoding="UTF-8"?><!-- - Application context definition for JPetStore's business layer. - Contains bean references to the transaction manager and to the DAOs in - dataAccessContext-local/jta.xml (see web.xml's "contextConfigLocation"). --> <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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.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">
调用1
调用2
调用3
提交事务关键在于事务2,你可以
1 强制使用REQUEST_NEW的配置参数
2 在B里面自己重新获得事务,代码
可以在执行A后把执行B所需要的地数据保存下来,
这样ABC回滚后,将数据给B,让B再执行一次(确保得到的和第一次完全一致的结果),模拟实现B没有回滚的状态。
给B开启一个单独的事务吧
A C 可以共用一个事务
同意老大,但是不是传播特性REQUEST_NEW这个是不是应该这么写REQUIRED_NEW ?不知道LZ看懂了么,给 B 指定事务传播为REQUIRED_NEW,不管别人怎么开事务,他自己会再新开一个,这样就不会受别的事务的影响了
- Application context definition for JPetStore's business layer.
- Contains bean references to the transaction manager and to the DAOs in
- dataAccessContext-local/jta.xml (see web.xml's "contextConfigLocation").
-->
<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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.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">
<!-- 通过hibernate.cfg.xml配置SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<!-- 引用 配置SessionFactory的ID-->
<ref bean="sessionFactory"/>
</property>
</bean>
<!-- 配置事务的传播性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 哪些方法有 事务的传播性-->
<tx:attributes>
<!-- 以add开始的方法 REQUIRED表示就用事务,没有就开启事务-->
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="select*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<!-- 除了上面的方法外,其余的方法都是只读 -->
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 哪些类的方法参与了事务 -->
<aop:config>
<!-- execution(* com.east.spring.managerimpl.*.*(..))这个类的所有方法都用事务 -->
<aop:pointcut id="allManagerMethod" expression="execution(* com.east.ssh.dao.impl.*.*(..))"/>
<!-- 引用 pointcut 和 advice-->
<aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/>
</aop:config>
</beans>