Inner transaction changes not visible to outer transaction?

REQUIRES_NEW doesn't mean nested transaction, spring starts another transaction suspending the one currently active. As far as the DB is concerned they are two independent transactions.

REQUIRES_NEW doesn't mean nested transaction, spring starts another transaction suspending the one currently active. As far as the DB is concerned they are two independent transactions. If you need a nested transaction you should use the attribute NESTED.

For this to work the database and driver need to support certain features - which I don't think is widely supported.

I did not mean nested transaction, fixed the title. As you said, the two are separate transactions, so changes from the inner transactions must be visible to the outer transaction. Even stranger fact is that if I move call to getFoo inside insertFooRelationAndUpdateBar, the test case succeeds.

– Lalit Mishra Oct 6 at 12:43 What is the isolation level - whether changes made to the DB after a transaction has been started are visible to it or not depends on the isolation level. Also in your example it is not clear what you mean by test fails - which is the inner and outer transaction? – gkamal Oct 6 at 13:19 Isolation is not changed i.e.It is default.

Outer transaction starts with the test method and the inner transaction starts with the insertFooRelationAndUpdateBar method which has the 'transactional' annotation with propagation=REQUIRES_NEW. By test failure, I mean the assertion fails because the relation which was added in the inner transaction is not visible to the test method. – Lalit Mishra Oct 6 at 15:01 The behavior is what you would get with isolation REPEATABLE_READ.

Try changing the isolation level on the @Transactional in test to READ_COMMITED. With isolation REPEATABLE_READ any query that was executed in a transaction is gauranteed to return the same data, that is why when you move the getFoo into the other transaction it works. – gkamal Oct 6 at 16:32.

You're asking why changes made in one transaction aren't visible in a second transaction. This is a primary reason that transactions are used: to keep changes isolated until commit. So you're kind of asking why relational databases work the way they do.

I am sorry that I've not been clearer about that. The inner transaction is committed (at-least the logs say so) after the end of method insertFooRelationAndUpdateBar. If getFoo is brought inside this method, same thing works.

– Lalit Mishra Oct 6 at 15:49 Right: one transaction is committed, but the other, which started first, is ongoing. Depending on the isolation level, the ongoing first transaction won't see something done by the second transaction. Granted there are probably several other things that could be wrong.

If you're looking for more concrete answers, ask a more concrete question--i.e. Provide an SSCCE. – Ryan Stewart Oct 6 at 22:34 I've edited the question with a concrete example.

And I think I get what you mean. I'll have to change the propagation for getFoo to REQUIRES_NEW, so that the retrieval also starts a new transaction which would be aware of changes made by the earlier transaction. Is there any other solution?

– Lalit Mishra Oct 7 at 11:48.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions