Results 1 to 4 of 4

Thread: Saving to database and properties file in same transaction

  1. #1
    Join Date
    Jun 2009
    Posts
    1

    Default 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. #2
    Join Date
    Jan 2008
    Location
    San Diego
    Posts
    780

    Default

    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:

    http://www.jboss.org/jbosstm/fileio/

  3. #3
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    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. #4
    Join Date
    Mar 2010
    Posts
    11

    Default

    Hi,

    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.

    Thanks,
    Nitin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •