Results 1 to 3 of 3

Thread: Transaction Configuration

  1. #1

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Jan 2008
    Location
    Southampton, UK
    Posts
    14

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •