Results 1 to 3 of 3

Thread: Transaction Manager with two databases

  1. #1
    Join Date
    Sep 2004
    Posts
    8

    Default Transaction Manager with two databases

    Hello.

    I'm doing very small command line application that imports some data from a database to another database using the JDBC helper classes.
    I have to write to the two databases:
    -In the destination database i write the imported data
    -In the source the database i write in a temporary table the data that was imported.

    Because It's a very small and simple application it doesn't use JTA but I would like to configure the transaction Manager to rollback if i enconter a problem in anyone of the databases.


    Can we do something like this?
    Code:
                transactionDest.execute(new TransactionCallback() {			
    				public Object doInTransaction(TransactionStatus arg0) {
    					transactionSource.execute(new TransactionCallback() {					
    						public Object doInTransaction(TransactionStatus arg0) {
    							migrateCompany(contractId);
    							return null;
    						}					
    					});
    					return null;
    				}			
    			});
    I don't think that this rollback the two databases in case of an error.
    What do you sugest?

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    First of all try to search the forums - I recall some some threads about this topic. I think you should do one of the following:

    1. use JTA
    2. write a facade transaction manager that will delegate the rollback to both databases
    3. search a solution outside Spring like C-JDBC.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3
    Join Date
    Sep 2004
    Posts
    8

    Default

    The migration is not going to be made in the contect of a full J2EE server so I can't use JTA.
    C-JDBC it seems to be a very complex solution to something this simple.
    Can you elaborate the second solution.

    I just need something simple like this:

    Code:
    try{
      db1.startTransaction();
      db2.startTransaction();
      doMigration();
      db1.commit();
      db2.commit();
    } catch(DataAcessException ex) {
      db1.rolback();
      db2.rollback();
    }
    I know that some cases this might not work (error on the second commit) but I can recover manually if that ever happens.

Similar Threads

  1. Unit testing with JOTM and JtaTransactionManager
    By lalle in forum Architecture
    Replies: 1
    Last Post: Oct 15th, 2005, 09:05 AM
  2. newbie question about custom transaction manager
    By jeroenbreedveld in forum Data
    Replies: 6
    Last Post: Sep 28th, 2005, 11:09 AM
  3. Replies: 0
    Last Post: Jun 6th, 2005, 06:22 AM
  4. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM
  5. Transaction pb Hibernate/MySQL
    By syluser in forum Data
    Replies: 2
    Last Post: Aug 28th, 2004, 02:40 PM

Posting Permissions

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