5.4. Transaction Management

Spring provides a declarative transaction model including transaction propagation semantics, to allow applications to declare transaction boundaries around specific methods either through annotation or through XML. The model is the same whether the transactions being used are local transactions or JTA transactions. Spring wraps components in a transactional proxy which delegates to a transaction manager; which is declared separately as a Spring bean. Through PlatformTransactionManager abstraction, Spring gives you a choice between using resource-local transactions and delegating to the transaction manager provided by the application server.
Transaction support in JBoss Enterprise Application Platform is provided by JBoss Transaction Service, a highly configurable transaction manager. To use the JBoss Transaction Service in a Spring application, use a Spring JTA transaction manager definition.

Example 5.20. JTA Transaction Manager Definition in Spring


<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManagerName" value="java:jboss/TransactionManager"/>
</bean>
The use of the transaction manager allows Spring to create JTA transactions (for example, through Spring declarative transaction management), or to enroll in existing transactions, if any. This requires the use of managed datasources, JTA-integrated session factories, or container-deployed persistence units. It ensures that the underlying database connections, sessions, and persistence contexts are managed transparently and shared with other components.