This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

AnnouncementAnnouncement Module

Collapse

No announcement yet.

Saving to database and properties file in same transactionPage Title Module

Saving to database and properties file in same transaction

I am using JPA(Hibernate implementation) to store entities in database .

I have a scenario wherein i need to save values to database and also some part of it to
a properties file(maintain preferences for some component). I am using commons configuration
for this .

I want that the transaction consists of both the saves to database and properties file as well .
There is a method in PropertiesConfiguration(commons config object) , save , what i want is
Spring to either call commit on connection and save on PropertiesConfiguration both or none .

An option worth considering is to use Spring's TransactionSynchronizationManager. You can register a TransactionSynchronization and add the save() method call within one of its methods (e.g. afterCompletion and check the status for COMMITED vs. ROLLED_BACK). It is not true 2PC, but it does allow you to have conditional invocation of a non-transactional resource based on the outcome of the transactional resource's operation.

Comment

Using XA transactions you can combine operations across multiple resources in a single global transaction. This would guarantee that either all of the operations commit or none of them commit. You need to configure your database's data-source to enable XA with database. As file-systems do not support XA, you can use XADisk to perform the file operations inside XA transactions.