Spring Mybatis based track action question.

Asked 2 years ago, Updated 2 years ago, 68 views

I would like to ask you a question about setting transaction boundaries in a spring mybatis-based environment.

 @Override
    @Transactional(readOnly = false, isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
    public void doSomeThing() {
        //database select (1)
        select()
        //database insert (2)
        insert()
        //message queue notification (3)
        noti();
    }

No. 3 noti() method always wants to be executed (asynchronized) with or without the failure of No. 1 and No. 2 track action.

Please give me some advice!

spring mybatis transaction

2022-09-21 20:13

1 Answers

The simplest way to make it simple is to use the phrase try~finally.

try {
         //database select (1)
        select()
        //database insert (2)
        insert()
} } finally {
        //message queue notification (3)
        noti();
}

If noti() does not have a reference in the DB for the previous select and insert, this can be easily resolved.

try~finally executes the try {} block after the try {} block ends, even if it ends with an exception.


2022-09-21 20:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.