Transaction Propagation Strategies in Spring
by, 11-27-2011 at 11:29 PM (3436 Views)
In the previous tip, we looked at the key properties that are required for handling any transaction. In Spring, when you want to have your application are using. Spring transaction concepts are taken from the JEE specification specifically the EJB 3.0 specification. Another key aspect of managing transactions is the ability to control the propagation of transactions in your application. Spring has the org.springframework.transaction.TransactionStatus interface that allows an application to check the status of the running transaction, irrespective of whether it is new, read-only, or rollback only. This interface also exposes a setRollbackOnly method that causes the current transaction to rollback and end rather than having a transaction abnormally terminate through an exception. As this interface is familiar to EJB CMT transaction attributes, Iíve outlined in the table below the different propagation strategy properties that can be defined either in XML or using annotations:
In Spring these rules are defined using the following convention, PROPAGATION_PROPERTY. So for example for the first one listed, REQUIRED, it will be PROPAGATION_REQUIRED. In a future tip, I will show you how to use Spring transaction capabilities in your application.