Java Reference
In-Depth Information
<<interface>>
Platform
Transaction
Manager
Transaction
Interceptor
Uses
getTransaction()
commit()
rollback()
invoke()
Hibernate
Transaction
Manager
JdoTransaction
Manager
JtaTransaction
Manager
...
Manages local
transactions
Manages global/JTA
transactions
Figure 7.2
The different implementations of the PlatformTransactionManager interface
Using local transactions
A local transaction involves only a single database, and can be started, committed,
and rolled back using the JDBC or persistence framework API s directly. Spring
provides several PlatformTransactionManager implementations for managing
local transactions; which one you use depends on how the application accesses
the database. A JDO application uses a JdoTransactionManager , which manages
transactions using the JDO Transaction interface, and a Hibernate application
uses a HibernateTransactionManager , which manages transactions using the
Hibernate Transaction interface. In addition, a JDBC application uses a Data-
SourceTransactionManager , which manages transactions using the JDBC Connec-
tion interface (this is described in more detail in chapter 9).
As well as managing transactions, these PlatformTransactionManager imple-
mentations manage a connection that can be used by the repositories that are
called during the transaction. Behind the scenes, they use a ThreadLocal to bind
the connection to the thread. Before starting the transaction, the JdoTransaction-
Manager opens a PersistenceManager , which can be obtained by the repositories
using PersistenceManagerFactoryUtils.getPersistenceManager() . It closes the
PersistenceManager after the transaction ends. Similarly, a HibernateTransaction-
Manager manages a Session , which the repositories can access by calling Session-
FactoryUtils.getSession() . Spring's ORM template classes use these methods to
get a persistence framework connection.
 
 
 
 
 
 
 
Search WWH ::




Custom Search