Results 1 to 2 of 2

Thread: consuming web services within a transaction

  1. #1

    Default consuming web services within a transaction

    Say I have an application that has a database that stores data, but I also update a legacy system via a web service. My first question, for people who have architected solutions like this, do you create a DAO layer for the web services that you are consuming? If so, does spring have/need a WebServicesDaoSupport that you can extend to make dealing with web services easier? My main question though is about transactions. Is there any way to design a web service that can participate in a transaction? So for example, say I have an object which I have to update in my legacy system as well as the database. Imagine I have a business layer manager with a method like this:

    Code:
    public void save(Object obj) {
        legacyDao.save(obj);
        databaseDao.save(obj);
    }
    Is there any easy way to design this so that if there is an exception thrown during databaseDao.save that the changes made during legacyDao.save are somehow rolled back?

  2. #2
    Join Date
    Dec 2004
    Location
    Bucuresti, Romania
    Posts
    72

    Default

    Hi,

    I think there is some specification on transaction propagation over web services. If this spec is implemented and your legacy web services use it, then you're lucky.

    Otherwise, just structure your code like this:
    Code:
        //tx start
        databaseDao.save(obj1);
        databaseDao.save(obj2);
        databaseDao.save(obj3);
    
       legacyDao.save(obj1);
       legacyDao.save(obj2);
       legacyDao.save(obj3);
      //tx end
    By this I mean you should structure your code so that the databaseDao calls occur in the first part of the transaction and the legacyDao calls in the second part of the transaction. Also, if you are using Hibernate or something simmillar be carefull that the hibernateSession.flush() is called in you databaseDao methods. Otherwise, the hibernateSession.flush() would be done automatically at the and of the transaction, after the calls to legacyDao.

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. Replies: 0
    Last Post: Jun 6th, 2005, 06:22 AM
  3. Replies: 3
    Last Post: May 16th, 2005, 07:04 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
  •