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

  • SEARCH
  • Home
  • 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 6324629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:44:25+00:00 2026-05-24T16:44:25+00:00

In first case study given at http://www.vermatech.com/code/SpringTransactionExamples.html , program is calling two methods i.e.

  • 0

In first case study given at http://www.vermatech.com/code/SpringTransactionExamples.html,
program is calling two methods i.e.

testModel.deleteAllCountries();
testModel.initializeCountries();

where initializeCountries throws runtime exception. For both methods’ transaction definition attribute is PROPAGATION_REQUIRED. Still transaction under deleteAllCountries
method gets committed but transaction under initializeCountries are rolled back(as per the logs given in the same case study).

As per PROPAGATION_REQUIRED definition is that it Support a current transaction; create a new one if none exists. So my question here is transaction under initializeCountries method
should support the transaction under deleteAllCountries method. I mean both method should be treated as single transaction. As per my understanding either complete transaction should be committed or rolled back? Not sure how come logs are treating them separately.

  • 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-24T16:44:26+00:00Added an answer on May 24, 2026 at 4:44 pm

    “Propagation required” is defined as

    Support a current transaction, create a new one if none exists.

    In your case above the deleteAllCountries method executes in a transaction and commits. There is no current transaction when initializeCountries is called, so it executes in a second transaction, and rolling it back has no effect on the changes made by the first method.

    Propagation applies to nested method calls, not to successive ones. If you look at the documentation:

    When the propagation setting is PROPAGATION_REQUIRED, a logical
    transaction scope is created for each method upon which the setting is
    applied. Each such logical transaction scope can determine
    rollback-only status individually, with an outer transaction scope
    being logically independent from the inner transaction scope. Of
    course, in case of standard PROPAGATION_REQUIRED behavior, all these
    scopes will be mapped to the same physical transaction. So a
    rollback-only marker set in the inner transaction scope does affect
    the outer transaction’s chance to actually commit (as you would expect
    it to).

    However, in the case where an inner transaction scope sets the
    rollback-only marker, the outer transaction has not decided on the
    rollback itself, and so the rollback (silently triggered by the inner
    transaction scope) is unexpected. A corresponding
    UnexpectedRollbackException is thrown at that point. This is expected
    behavior so that the caller of a transaction can never be misled to
    assume that a commit was performed when it really was not. So if an
    inner transaction (of which the outer caller is not aware) silently
    marks a transaction as rollback-only, the outer caller still calls
    commit. The outer caller needs to receive an
    UnexpectedRollbackException to indicate clearly that a rollback was
    performed instead.

    then you can see all of this is about inner- and outer-, none of it mentions successive calls. In your case the call to deleteAllCountries is the outermost transactional method, so when it finishes successfully then Spring commits the transaction immediately. Then your call to initializeCountries has to be executed within a separate transaction, where it is the outermost method.

    Your assumption seems to be that Spring will hold the transaction open after the first method finishes, but that’s not how it works. In order to get the effect you want, you could create another method on testModel that wraps the calls to deleteAllCountries and initializeCountries, make that method transactional and give it the attribute PROPAGATION_REQUIRED. That way a rollback of the second method will cause the first method’s changes to be rolled back too, because the wrapping method is grouping them together. Otherwise nothing is telling Spring these things should be part of the same transaction.

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

Sidebar

Related Questions

I downloaded a program implemented in Java (in this case, http://julian.togelius.com/mariocompetition2009/index.php ). I first
In two different views I have the following two pieces of code. FIRST <table
Why in the first case, html em tags are printed normally whereas in the
In C it's possible to write code before the first case label. Are there
RewriteCond %{QUERY_STRING} ^id=(.*)$ RewriteRule ^oldpage\.php$ http://new-site.com/newpage-%1 [R=301,L] and RewriteRule ^oldpage\.php$ http://new-site.com/newpage-%1? [R=301,L] In first
Imagine I have a method: void Method(bool parameter){ if(parameter){ // first case } else
Why does the compiler say a constant value is required for the first case...the
I did the following to upper case the first letter in each word but
First of all (in case this is important) I'm using ActiveState's Perl (v5.8.7 built
First I'll lay out what I'm trying to achieve in case there's a different

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.