Announcement Announcement Module
No announcement yet.
Starting new transaction(s) from existing without suspending Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Starting new transaction(s) from existing without suspending

    We have a situation where we have written a new object to the database and from that method would like to start multiple potential new transactions related to the new object. That is, we need to have some other business logic examine the new object and possibly create a mapping refering to the new object.

    It would seem that we might accomplish this by calling another method which has the RequiresNew transaction property for each of these possible mappings, but that doesn't seem to be working.

    Does the initial transaction need to be committed somehow before calling the second method? If so, how should this be done?

    Are we missing something obvious?

  • #2
    REQUIRES_NEW will suspend the existing transaction and create a new one for the scope of the given method (which will execute independently from the existing transaction, not participating in the existing locks etc). Afterwards, the previous transaction will be resumed again (just like with EJB CMT's transaction attribute of the same name).

    NESTED will create a savepoint in the existing transaction and continue with the given method. If the method causes a rollback, it will roll back the transaction to the previous savepoint. All of this will happen in the same transaction: It's just possible to roll back to a previous state of the transaction here. (This is not supported by EJB CMT.)

    What are your requirements? Why do you need to execute those suboperations in new transactions?



    • #3
      The requirements are first to write a new object to the database (it should be committed). Then to initiate some business logic examining this new object. The business logic will add entries into a many-to-one mapping from other objects in the database to this new object.

      So what we want is to complete the first transaction and then probably create other new transactions all of which should be independent.

      We were trying to do this out of a single SLSB.


      • #4
        Then you probably want to create the first new object in a service wrapped with a REQUIRES_NEW transaction. If that succeeds, then you can call other code which is just wrapped with REQUIRES.