@Transactional propagation = Propagation.REQUIRES_NEW

We have this behaviour in our environment.

Hibernate 5.6.14.Final
SpringBoot 2.7.7

We call a method (method1) with annotation @Transactional; inside the method1 we call another method (method2) with annotation @Transactional(propagation = Propagation.REQUIRES_NEW).

In the method2 we have one insert and one update in table.
When exiting from method1 the same update and insert in table occur causing a data integrity violation.

How can we make the changes made in method2 visible to method1 so that the second insert/update does not occour? Thanks in advance

Thanks in advance.

This depends on the transaction isolation level that you used. Using SNAPSHOT isolation (also known as repeatable read) will not work. You have to configure the READ COMMITTED isolation level. Since you start the first transaction with method1 before the second in method2, the first transaction would never see anything that happens after it started when using SNAPSHOT isolation.

Hi Beikov,

thanks for the hint; but as far as I know for PostgreSQL (the database engine we use) READ COMMITTED is the default isolation level.

In that case, you’d need to share your code with us. What does method1 and method2 do? How do the entities look like?

Hi @lromano

Try putting method2 in another class
Just guessing…