Multiple Transaction Managers
You have choice of declaring any number of transaction managers and then supplying to the transaction advices and according these will be applied by Spring transparently to the source code using Spring’s AOP. Listing 9-10 uses two transaction manager, JDBC and JPA. LoyaltyService class methods use the JDBC transaction management and CustomerService class methods use the JPA transaction management.
Listing 9-10. Multiple transaction manager usage in declarative transaction management
<!–—JDBC transaction manager configuration (DataSource) – Start —->
<!–—JPA transaction manager configuration (Entity Manager) – Start—->
<!– Use Hibernate as JPA engine –>
Different transaction properties for different beans
Listing 9-10 shows different beans being applied with different transaction properties using multiple transaction advices. These transaction advices are used to configure the various transaction attributes.
Rolling back rules in a declarative transaction
It is possible to control rolling back rules using transaction advices, as shown in Listing 9-11 and Listing 9-12, with each example displaying a particular way of configuring the rolling back rule.
Listing 9-11. Rolling back transaction for a particular exception class namely “MyException”
Listing 9-12. No rolling back of transaction for a particular exception class namely “MyOwnException”
If multiple rolling-back and non-rolling-back rules are configured, the Spring framework evaluates all the rules and the strongest matching rule wins. A specific rule wins over generic rules similar to the catch block execution in the case of Java exception handling.
Page Visitors: 8819