An external transaction in the nested case of using transactions does not see updates stored in the database (JPA, MySQL, Spring Framework and Hibernate)

I have a case when a transaction is started and a method is called along the path (in the code) that starts a new transaction. When the internal transaction is completed, the data is stored in the database, but the data is not visible from the external transaction.

Here are the code snippets.

@Transactional(readOnly = true)
public void doSomething() {
    // Some stuff happens here
    doMoreStuff();
    // Some more stuff happens here.
}

@Transactional(propagation = Propagation.REQUIRES_NEW)
public void doMoreStuff() {
    ...
}

The doMoreStuff method updates some data in the database, after which the doSomething method should see the updated data, but this is not so. For example, "doMoreStuff" sets a boolean value from false to true and saves it. The doSomething method still only sees false.

Any suggestions?

+1
source share
2

, "" Hibernate ( , MySQL ).

, () (?) - "" , "" .

, , , MySQL, REPEATABLE READ, - , .

, ( ) READ COMMITTED , .

+1

- - Propagation.PROPAGATION_NESTED

+1

Source: https://habr.com/ru/post/1783210/


All Articles