Java Reference
In-Depth Information
The
DataSourceTransactionManager
works with a
javax
.
sql
.
DataSource
object. It ensures
that the same
Connection
object is retrieved from the
DataSource
and used in a transac-
tion. If the transaction is successful, the commit method is invoked on the
Connection
object. If the transaction is a failure, the rollback method will be used. In short, this trans-
action manager delegates the actual transaction processing to the database.
Hibernate Transactions
HibernateTransactionManager
can be used to manage transactions if your application uses
Hibernate ORM to manage application persistence. This transaction manager works
with the Hibernate
SessionFactory
object. It delegates the transaction handling to the
org.hibernate.Transaction
object retrieved from the Hibernate
Session
object. The
commit and rollback methods will be called on this
Transaction
object depending on suc-
cessful and failed transactions, respectively. The
HibernateTransactionManager
is wired in
the Spring configuration, as shown in Listing 6-27.
Listing 6-27.
transaction-config.xml
<beans>
<bean id="hibernateTransactionManager" class="org.springframework.
å
orm.hibernate.HibernateTransactionManager
">
<property name="sessionFactory
" ref="hibernateSessionFactory
"/>
</bean>
<beans>
JPA Transactions
The Java Persistence API is the new persistence standard in EJB 3, replacing the
widely disliked entity beans. Spring also supports JPA transactions through the
JpaTransactionManager
. This is configured in the Spring application context, as in
Listing 6-28.
