Announcement Announcement Module
Collapse
No announcement yet.
consuming web services within a transaction Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment

    Working...
    X