#3407 Honor isolation level on read-only transactions - #3874
Conversation
Read-only TxScope previously ignored isolation when creating ImplicitReadOnlyTransaction. Apply setIsolationLevel after createReadOnlyTransaction so @transactional(readOnly=true, isolation=...) and TxScope setReadOnly+setIsolation take effect.
|
Do you have an application hitting this issue or is it more a bug fix for a known issue? If you have an application hitting this, what database and isolation level is being used? Can you explain the use case? Do you have a workaround? |
|
@rbygrave Honest answer: I don't have a production app hitting this myself — the fix comes from the known issue #3407 reported by @rPraml. Reporter's use case (from the issue): they hold update locks on certain tables and wanted some UI queries on a read-only connection at Workaround they used: skip the read-only connection (use a normal transaction) when a non-default isolation is required. This PR: when If you'd rather keep isolation unsupported on the read-only pool for product reasons (e.g. only useful on DB2), happy to close or narrow — just say the word. |
Summary
Fixes #3407 — when a method (or
TxScope) is read-only and specifies an isolation level, Ebean dropped the isolation and always used the connection default (typicallyREAD_COMMITTED).Root cause
TransactionManager.createTransaction(TxScope)used the read-only path without applying isolation:Fix
After creating the read-only transaction, apply the same
setIsolationLevelhelper used by normal transactions:When isolation is unset (
-1), behavior is unchanged.Tests
TestTransactionalReadOnly#test_readonly_honors_isolation— programmaticTxScope.required().setReadOnly(true).setIsolation(SERIALIZABLE)TestTransactionalReadOnly#test_readonly_annotation_honors_isolation—@Transactional(readOnly = true, isolation = SERIALIZABLE)Notes
Isolation is still only as useful as the target database allows (e.g. some platforms map or reject
READ_UNCOMMITTED). This change ensures the requested level is applied to the JDBC connection for read-only scopes when the platform supports it.