Below is my configuration for transactions
Code:
<bean id="TransactionProxyCreator"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="interceptorNames">
<list>
<value>SpringTransactionInterceptor</value>
</list>
</property>
<property name="beanNames">
<value>*Service</value>
</property>
</bean>
<bean id="TransactionAttributes"
class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
<property name="properties">
<value>
*=PROPAGATION_REQUIRED
</value>
</property>
</bean>
<bean id="SpringTransactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="JTATxManager" />
</property>
<property name="transactionAttributeSource">
<ref bean="TransactionAttributes" />
</property>
</bean>
<bean id="JTATxManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="autodetectTransactionManager" value="false" />
</bean>
Below is the method in service class OrderService.java
Code:
public void updateOrders()
{
List<Future<Integer>> queryTasks = new ArrayList<Future<Integer>>();
for(int i=4521;i<4526;i++)
{
Future<Integer> queryTask = this.getTestDao().updateOrderId(i);
queryTasks.add(queryTask);
}
}
Below is the Dao method which is asynchronous
Code:
@Async
public Future<Integer> updateOrderId(int orderNo)
{
int result = this.update("updateOrderStatusForId", orderNo);
System.out.println("@@@@@@@@@@@@@@@@@@@@@@@ Update successful");
return new AsyncResult<Integer>(result);
}
I need all the orders from 4521 to 4526 to be rolled back if any one of them fails. Currently none are rolled back.