Announcement Announcement Module
Collapse
No announcement yet.
Transaction Configuration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transaction Configuration

    I have been unable to find the answer to what seems like a simple questions. How do you configure spring to manage transactions across service level methods? For example if I wanted to do something similar to :

    serviceA.save();
    if(condition == true)
    serviceB.save();


    As is configuration stands now the two service calls run in two separate transactions. Is there a way to run these within one transaction or is this simply bad design?

    Cheers.

  • #2
    Code:
    serviceA.save();
    if(condition == true)
    serviceB.save();
    The code above should be wrapped in another service which is transactional and thus 1 transaction is created.

    Comment


    • #3
      Expanding on mdeinum's response, when you're nesting transactions, you can configure how Spring should behave. See: http://static.springframework.org/sp...efinition.html

      You're interested in applying PROPAGATION_REQUIRED to serviceA, serviceB and the enclosing service (the one described by mdeinum). This means that if Spring finds a transaction already open, it'll re-use it. If it doesn't find one, it'll open a new one.

      Comment

      Working...
      X