I know the use and the basic understanding behind both @transaction and @transaction(readOnly=true)
.
But in my project, in one service I have used @transaction(readOnly=true)
-->> where it did all CRUD operations. While in my another service it did not let me update the table. I have to remove "readOnly=true".
I simply don't understand how it is allowing in one service to do all the operations and in other does not. Is there something I am missing about the basic understanding of this concept?
It’s only a hint.the readOnly parameter doesn’t guarantee its behaviour, is only a hint that may or may not be taken into account.Source
This just serves as a hint for the actual transaction subsystem; it will not necessarily cause failure of write access attempts. A transaction manager which cannot interpret the read-only hint will not throw an exception when asked for a read-only transaction but rather silently ignore the hint.
it’s closely related to the propagation setting. For example: for SUPPORT, readOnly flag won’t ever be used; for REQUIRES_NEW always; for REQUIRED it depends on whether we already are in the transactional context or not, etc.