pesche666
pesche666

Reputation: 179

Spring Batch with two databases

I have a Spring Batch application that uses two databases. One for the job repository and a database that contains business data. At the moment I am using two different transaction managers for these datasources, but some guys at my company suggest to use a single JTA TransactionManager (with XA). Is this really correct? If a transaction to the business database fails this would mean that any updates to the job repository are also rolled back? Which is probably not desirable. What is the best practice in such a scenario?

Upvotes: 2

Views: 1079

Answers (2)

Ashoka
Ashoka

Reputation: 941

For two different data-sources, it's probably better to Use an XADataSource and a transaction manager like Atomikos. However based on your inputs, the 2 data-sources need not be under a single transaction manager, as the job repository is a state management strategy. I'd probably suggest wiring 2 different transaction managers. Check out this here link from the Spring Forums : 2 Datasources

Upvotes: 0

Zava
Zava

Reputation: 400

IMHO, using JTA to tie the two datasources is not a good choice. Imagine if the business transaction rolls back, at this time, if JTA is enabled, you won't be able to commit spring batch transaction and thus you won't be able to update the current state of your batch in spring batch database.

You can try though, force a rollback on the business transaction and see the impacts.

Hope it helps.

Upvotes: 1

Related Questions