Announcement Announcement Module
No announcement yet.
Saving to database and properties file in same transaction Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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 .

    How can this be achieved ?

    Thanks in advance .

  • #2
    You can't achieve true transactional semantics with the configuration that you've described because the properties configuration does not support ACID.

    You'd need to look into using something like this:


    • #3
      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.


      • #4

        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.

        Hope that helps.