[CONJ-786] Connection.setReadOnly has no effect Created: 2020-04-28  Updated: 2020-05-14  Resolved: 2020-05-14

Status: Closed
Project: MariaDB Connector/J
Component/s: pooling
Affects Version/s: 2.5.4, 2.6.0
Fix Version/s: 2.6.1

Type: Bug Priority: Major
Reporter: Cheong Chung Onn Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None
Environment:

Ubuntu 18.04, 10.4.12-MariaDB-1:10.4.12+maria~bionic-log



 Description   

Wanted to create a read-only transaction using jConnector. Expect Mariadb to return a java.sql.SQLException when there is an update statement within a read only transaction

See the code below.

1. Mariadb commits the the statement and return success
connection.setAutoCommit(false);
connection.setReadOnly(true);
– do an update statement
connection.commit();

2. Mariadb returns an exception, 'set transaction read only' is sent to Mariadb prior to starting an update statement.

connection.createStatement().execute("set transaction read only")
– do an update statement //Cause Mariadb to return a SqlException



 Comments   
Comment by Diego Dupin [ 2020-05-14 ]

This is implemented only for multiple host (https://mariadb.com/kb/en/about-mariadb-connector-j/#failover-and-load-balancing-modes)
but not for single host configuration.

Default configuration doesn't force read-only, but this can be set using option "assureReadOnly"

That will be added in 2.7 version for single host with same behaviour (option
"assureReadOnly")

Generated at Thu Feb 08 03:18:18 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.