Transaction support and the Spring Framework
For Spring Framework Version 2.5 or later, you can use the declarative transaction model, use the Spring Framework support for the AspectJ programming extension, or use annotation-based transaction support. For versions of the Spring Framework earlier than Version 2.5, and for versions of the application server that do not provide the UOWManager interface, you can use a Spring Framework configuration that supports a restricted set of transaction attributes.
Declarative transaction model
WebSphere® Application Server Version 6.0.2.19 or later and Version 6.1.0.9 or later support the Spring Framework declarative transaction model to drive resource updates under transactional control. The WebSphereUowTransactionManager class in Spring Framework 2.5 uses the UOWManager interface in the application server to manage the transaction context. Because transaction demarcation is managed through the UOWManager interface, an appropriate global transaction or local transaction containment (LTC) context is always available when a resource provider is accessed. For more information about the UOWManager interface and Java™ Transaction API (JTA) support, see the related topic.
- PROPAGATION_REQUIRED
- PROPAGATION_SUPPORTS
- PROPAGATION_MANDATORY
- PROPAGATION_REQUIRES_NEW
- PROPAGATION_NOT_SUPPORTED
- PROPAGATION_NEVER
<bean id="transactionManager"
class="org.springframework.transaction.jta.WebSphereUowTransactionManager"/>
<bean id="someBean" class="some.class">
<property name="transactionManager" >
<ref bean="transactionManager"/>
</property>
...
</bean>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
The AspectJ programming extension
- All methods that start with the string
get
have the transaction attribute PROPAGATION_REQUIRED. - All methods that start with the string
set
have the transaction attribute PROPAGATION_REQUIRES_NEW. - All other methods use the default transaction settings.
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" propagation="REQUIRED" read-only="true" />
<tx:method name="set*" propagation="REQUIRES_NEW" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="myServiceOperation"
expression="execution(* sample.service.MyService.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="myServiceOperation"/>
</aop:config>
Annotation-based transaction support
To use the annotation-based transaction support, you need Java Platform, Standard Edition 5 (Java SE 5) or later. Therefore, you can use this method with WebSphere Application Server Version 6.1 or later.
<tx:annotation-driven/>
@Transactional
annotation,
for example:@Transactional(readOnly = true)
public String getUserName()
{ ...
}
You can use the @Transactional
annotation
to annotate only public methods.
Transaction support with Spring Framework before Version 2.5
You can use a Spring Framework configuration that supports a restricted set of transaction attributes.
You can use this method of transaction support with versions of the Spring Framework before Version 2.5 that do not provide the WebSphereUowTransactionManager class. You can also use this method of transaction support with versions of WebSphere Application Server earlier than Version 6.0.2.19 and Version 6.1.0.9 that do not provide the UOWManager interface.
- PROPAGATION_REQUIRED
- PROPAGATION_SUPPORTS
- PROPAGATION_MANDATORY
- PROPAGATION_NEVER
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="autodetectTransactionManager"value="false" />
</bean>
- PROPAGATION_REQUIRES_NEW
- PROPAGATION_NOT_SUPPORTED
WebSphere Application Server does not support the use of the Spring Framework class org.springframework.transaction.jta.WebSphereTransactionManagerFactoryBean.