img
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
This section covered some major configurations that you will deal with when processing
transactions on a day-to-day basis. For special cases, you may need to define the timeout, isolation level,
rollback (or not) for specific exceptions, and so on.
Note Spring's JpaTransactionManager doesn't support a custom isolation level. Instead, it will always use
the default isolation level for the underlying datastore. If you are using Hibernate as the JPA service provider, there
is a workaround when supporting a custom isolation level by extending the HibernateJpaDialect class (for
details, please refer to the article at http://amitstechblog.wordpress.com/2011/05/31/supporting-custom-
isolation-levels-with-jpa).
Using XML Configuration for Transaction Management
Another common approach of declarative transaction management is to use Spring's AOP support.
Before Spring version 2, we needed to use the TransactionProxyFactoryBean class to define transaction
requirements for Spring beans. However, ever since version 2, Spring provides a much simpler way by
introducing aop-namespace and using the common AOP configuration technique for defining transaction
requirements.
In this section, the example we will use is the same as the annotation one. We will just modify it to
the XML configuration style. Listing 13-18 shows the XML configuration file for transaction management
(tx-declarative-app-context.xml).
Listing 13-18. XML Configuration for Transaction Management
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
<aop:config>
<aop:pointcut id="serviceOperation" expression=
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home