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 6945129
In Process

The Archive Base Latest Questions

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

Can someone explain the isolation & propagation parameters in the @Transactional annotation via a

  • 0

Can someone explain the isolation & propagation parameters in the @Transactional annotation via a real-world example?

Basically when and why I should choose to change their default values?

  • 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-27T13:23:48+00:00Added an answer on May 27, 2026 at 1:23 pm

    Good question, although not a trivial one to answer.

    Propagation

    Defines how transactions relate to each other. Common options:

    • REQUIRED: Code will always run in a transaction. Creates a new transaction or reuses one if available.
    • REQUIRES_NEW: Code will always run in a new transaction. Suspends the current transaction if one exists.

    The default value for @Transactional is REQUIRED, and this is often what you want.

    Isolation

    Defines the data contract between transactions.

    • ISOLATION_READ_UNCOMMITTED: Allows dirty reads.
    • ISOLATION_READ_COMMITTED: Does not allow dirty reads.
    • ISOLATION_REPEATABLE_READ: If a row is read twice in the same transaction, the result will always be the same.
    • ISOLATION_SERIALIZABLE: Performs all transactions in a sequence.

    The different levels have different performance characteristics in a multi-threaded application. I think if you understand the dirty reads concept you will be able to select a good option.

    Defaults may vary between difference databases. As an example, for MariaDB it is REPEATABLE READ.


    Example of when a dirty read can occur:

      thread 1   thread 2      
          |         |
        write(x)    |
          |         |
          |        read(x)
          |         |
        rollback    |
          v         v 
               value (x) is now dirty (incorrect)
    

    So a sane default (if such can be claimed) could be ISOLATION_READ_COMMITTED, which only lets you read values which have already been committed by other running transactions, in combination with a propagation level of REQUIRED. Then you can work from there if your application has other needs.


    A practical example of where a new transaction will always be created when entering the provideService routine and completed when leaving:

    public class FooService {
        private Repository repo1;
        private Repository repo2;
    
        @Transactional(propagation=Propagation.REQUIRES_NEW)
        public void provideService() {
            repo1.retrieveFoo();
            repo2.retrieveFoo();
        }
    }
    

    Had we instead used REQUIRED, the transaction would remain open if the transaction was already open when entering the routine.
    Note also that the result of a rollback could be different as several executions could take part in the same transaction.


    We can easily verify the behaviour with a test and see how results differ with propagation levels:

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations="classpath:/fooService.xml")
    public class FooServiceTests {
    
        private @Autowired TransactionManager transactionManager;
        private @Autowired FooService fooService;
    
        @Test
        public void testProvideService() {
            TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
            fooService.provideService();
            transactionManager.rollback(status);
            // assert repository values are unchanged ... 
    }
    

    With a propagation level of

    • REQUIRES_NEW: we would expect fooService.provideService() was NOT rolled back since it created its own sub-transaction.

    • REQUIRED: we would expect everything was rolled back and the backing store was unchanged.

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

Sidebar

Related Questions

Can someone explain me with some example the difference beteen Apply and Eval in
Can someone explain what is the operator &= for? I searched, but I got
Can someone explain to or link to an article that explains how the parameters
Can someone explain to me if I should use bcpow() instead of pow() and
Can someone explain why the HashMap acts like it does in this example: Simple
Can someone explain dependency injection with a basic .NET example and provide a few
can someone explain to me what it means? LOG=/etc/security/aixpert/log/aixpert.log exec 1>>$LOG exec 2>&1 I
Can someone explain to me how exactly the NSTimer behavior is? Basically I want
Can someone explain the mechanics of a jump table and why is would be
Can someone explain to me the advantages of using an IOC container over simply

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.