Java Reference
In-Depth Information
How It Works
PlatformTransactionManager is a general interface for all Spring transaction managers. Spring has
several built-in implementations of this interface for use with different transaction management APIs:
If you have to deal with only a single data source in your application and access it
with JDBC, DataSourceTransactionManager should meet your needs.
If you are using JTA for transaction management on a Java EE application server,
you should use JtaTransactionManager to look up a transaction from the
application server. Additionally, JtaTransactionManager is appropriate for
distributed transactions (transactions that span multiple resources). Note that
while it's common to use a JTA transaction manager to integrate the application
servers' transaction manager, there's nothing stopping you from using a stand-
alone JTA transaction manager such as Atomikos.
If you are using an object/relational mapping framework to access a database, you
should choose a corresponding transaction manager for this framework, such as
HibernateTransactionManager and JpaTransactionManager .
Figure 4-2 shows the common implementations of the PlatformTransactionManager interface
in Spring.
Figure 4-2. Common implementations of the PlatformTransactionManager interface
A transaction manager is declared in the Spring IoC container as a normal bean. For
example, the following bean configuration declares a DataSourceTransactionManager instance.
It requires the dataSource property to be set so that it can manage transactions for connections
made by this data source.
<bean id= " transactionManager "
class= " org.springframework.jdbc.datasource.DataSourceTransactionManager " >
<property name= " dataSource " ref= " dataSource " />
</bean>
Search WWH ::




Custom Search