spring-framework / org.springframework.jdbc.datasource / DataSourceTransactionManager / setEnforceReadOnly

setEnforceReadOnly

open fun setEnforceReadOnly(enforceReadOnly: Boolean): Unit

Specify whether to enforce the read-only nature of a transaction (as indicated by TransactionDefinition#isReadOnly() through an explicit statement on the transactional connection: "SET TRANSACTION READ ONLY" as understood by Oracle, MySQL and Postgres.

The exact treatment, including any SQL statement executed on the connection, can be customized through through #prepareTransactionalConnection.

This mode of read-only handling goes beyond the Connection#setReadOnly hint that Spring applies by default. In contrast to that standard JDBC hint, "SET TRANSACTION READ ONLY" enforces an isolation-level-like connection mode where data manipulation statements are strictly disallowed. Also, on Oracle, this read-only mode provides read consistency for the entire transaction.

Note that older Oracle JDBC drivers (9i, 10g) used to enforce this read-only mode even for Connection.setReadOnly(true. However, with recent drivers, this strong enforcement needs to be applied explicitly, e.g. through this flag.

Since
4.3.7

See Also
#prepareTransactionalConnection