Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6978681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:47:17+00:00 2026-05-27T17:47:17+00:00

The situation is as follows: Method1 has four database update methods in it. The

  • 0

The situation is as follows:

  1. Method1 has four database update methods in it. The Method1 is annotated using the Spring transaction management semantics.

  2. Method2 has a database read method in it and it is invoked after Method1 has finished executing all its database updates. Method2 is also annotated using the Spring transaction semantics.

  3. There’s a web request that comes in, the controller intercepts the request and invokes method1 and then method2.

  4. A transaction is wrapped around the web-request as well.

What I am interested in knowing is:

1.How does Spring know to commit the database updates upon a successful transaction? Is there some reference to the Spring implementation that does the transaction management?

2.Since we have a hierarchy of transactions:
Transaction around the web-request->Transaction with Propagation=RequestNew for Method1->Transaction with Propagation=Required for Method2, how does Spring do the transaction management to ensure the transactions are executed within the proper context with the right order?

In short, it will be great to get a play by play account of how Spring performs the transaction management in all its grittiest details or a reference to documentation that doesn’t simply hand-wave an explanation centered around JTA or some other acronym.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:47:18+00:00Added an answer on May 27, 2026 at 5:47 pm

    Lets make some basic statements.

    1. A transactional context is an environment where some special properties (database session) are made available to the application runtime which are otherwise not available. A Transaction Context is generally used to scope a transaction.
    2. Spring uses, AOP Proxies and XML metadata to achieve a Declarative transaction management.
    3. Annotations are used to mark the Transaction Propagation behavior of a particular method.
    4. Spring uses Interceptor Mechanism to apply the transaction over the methods.

    Here I am reusing the example give by @stacker above

    MyClass{
    
        @Transactional
        public void sequence() {
          method1();
          method2();
        }
    
        @Transactional
        void method1() {
        }
    
        @Transactional(propagation=Propagation.REQUIRES_NEW)
        void method2() {
        }
    
    }
    

    You can also achieve the same functionality using xml configuration as well. Lets take this as its popular and widely used.

    At the time of deployment

    • Spring framework checks the xml configuration files (famed applicationContext.xml) and depending on the configuration, scans the code for @Transactional annotation (assuming that the configuration is mentioned as annotation based).
    • After this, it generates AOP proxies for methods marked for transaction. In simple terms, these proxies are nothing but wrapper around the concerned methods.
    • Within these wrapper methods, before and after a Transaction Advisor code is also generated depending on the configuration (namely the transaction propagation).
    • Now when these wrapper methods are invoked Transaction Advisor comes into picture before and after the actual method call. .
    • Representing the same in pseudo code for the example above

        ProxyMyClass{   
          MyClass myclass;
          .
          .
          .
          sequence(){
           //Transaction Advisor code (Typically begin/check for transaction)
           myclass.sequence();
           //Transaction Advisor code(Typically rollback/commit)
          }
          .
          .
          .
          }
      

    This is how spring managers the transaction. A slight oversimplification though.

    Now to answer your questions,

    .How does Spring know to commit the database updates upon a successful transaction? Is there some reference to the Spring implementation that does the transaction management?

    Whenever you call a method under transaction, you actually call a proxy which first executes the transaction advisor (which will begin the transaction), then you call the actual business method, once that completes, another transaction advisor executes (which depending on way method returned, will commit or rollback transaction).

    Since we have a hierarchy of transactions: Transaction around the web-request->Transaction with Propagation=RequestNew for Method1->Transaction with Propagation=Required for Method2, how does Spring do the transaction management to ensure the transactions are executed within the proper context with the right order?

    In case of transaction hierarchy, the spring framework generates the Transaction Advisor checks accordingly. For the example you mentioned,

    • for method1 (RequestNew ) Transaction Advsor code (or transaction Advice) would be to create a new transaction always.
    • for method2 (Required ) Transaction Advisor code (or transaction Advice) would be check for existing transaction and use the same if it exists or else create a new transaction.

    There is an image on the spring documentation page which very nicely summarizes these aspects.

    Typical Spring Transaction Management

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the situation is as follows, i have a page to add/update user in the
I have a situation as follows <body> Test<br /> test<br /> test1<br /> </body>
Our situation is as follows, but I'm curious about this problem in any situation.
The situation is as follows: A series of remote workstations collect field data and
The situation is as follows: I've got 2 models: 'Action' and 'User'. These models
Picture the following situation. I have an XML document as follows, <Form> <Control Type=Text
Situation: A PHP application with multiple installable modules creates a new table in database
The current situation is as follows: We have an production .net 3.5 WCF service,
Situation is as follows: There is a separate object that is responsible for generating
My WinForms application has a TextBox that I'm using as a log file. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.