I am while using H2 database embedded inside a Spring-MVC application.

I've declare Transactions inside my service level. Particularly I've got a situation where we all do the folllowing:

  1. Begin a transaction
  2. Create a webservices call
  3. Result in the subsequent database calls
  4. Upon rollback (the best), the webservices call is by hand folded back, and also the Spring Transaction Manager handles calling a rollback around the DB transaction.

However I recognized that the presence of the webservices call inside the DB transaction is leading to a table-wide lock, which in turn causes other customers to get errors (I'm able to produce this on the 1-user system with 2 browsers).

I'm attempting to plot my best strategy.

  • Must I be altering the transaction isolation level in Spring, will affecting the DB securing?
  • Could it be just bad form to possess a webservice and DB get in touch with exactly the same transaction?
  • Must I enable row level securing inside the H2 DB due to this?
  • Shall We Be Held not considering other solutions?

I ought to include that my service method serviceA() calls two other techniques webServiceX() and daoMethodY(). serviceA() is placed inside a transaction because any exception must rollback both webServiceX() (a function Provided), and rollback the daoMethodY() database procedures (a purpose of the DataSourceTransactionManager).

I believe your approach is affordable, and you ought to certainly try row-level securing whether it's possible.

You might like to reconsider your design. May be the database copying condition which really comes on the internet service? For the reason that situation, you might like to consider caching the net service calls rather. But that is dependent in your application.

Alternatively, you may have to roll your personal transaction management. As lengthy as it is generic, it should not be an excessive amount of trouble. We have carried this out within our project where we are not using Spring's transactions. Something similar to

performTransaction() {
    doWSCall();
    // no need to worry about WS call exception, because DB call won't happen
    try {
        doDbCall()
    } catch (Exception ex) {
        rollbackWSCall()
        // rethrow ex
    }
}

where all of the techniques are abstract.

I would not possess a web service call mingled right into a database call. Your technique is smashing the rule that states "do one factor well".

Have your merchandise call other web services and also the DAO.