Using transactions with a database
This recipe will show you how to set up transaction management over a database used from a Camel route. It will also detail the transaction propagation behaviors that you can use to combine both transactional and non-transactional database interactions.
Getting ready
The Java code for this recipe is located in the org.camelcookbook.transactions.databasetransaction
package. The Spring XML files are located under src/main/resources/META-INF/spring
and prefixed with databaseTransaction
.
As discussed in the Introduction section, Camel's transaction handling relies on Spring's PlatformTransactionManager
abstraction. Therefore, it is necessary to include the appropriate dependency in your application regardless of whether you are basing it on Spring or not—this includes regular Java as well as OSGi Blueprint applications.
To use Spring-managed JDBC transactions, you will need the following Maven dependencies:
<dependency> <groupId>org.apache.camel<...