I’m working on a Kotlin project (v1.9.23) where I use Exposed ORM v0.52.0 to perform operations in MySQL.
The insert transaction is declared as :
transaction(transactionIsolation = TRANSACTION_READ_COMMITTED, db = someDB) {
TestTable.insert {
it[date] = LocalDateTime.now()
}.resultedValues!!.first()
}
And a few times a day i get the error:
java.sql.SQLException: Cannot execute statement in a READ ONLY transaction.
org.jetbrains.exposed.sql.statements.Statement.executeIn$exposed_core(Statement.kt:99)
org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:292)
org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:269)
org.jetbrains.exposed.sql.statements.Statement.execute(Statement.kt:59)
org.jetbrains.exposed.sql.QueriesKt.insert(Queries.kt:161)
ThreadLocalTransactionManagerKt.inTopLevelTransaction$run(ThreadLocalTransactionManager.kt:324)
…calTransactionManagerKt.access$inTopLevelTransaction$run(ThreadLocalTransactionManager.kt:1)
…LocalTransactionManagerKt$inTopLevelTransaction$1.invoke(ThreadLocalTransactionManager.kt:371)
…ransactionManagerKt.keepAndRestoreTransactionRefAfterRun(ThreadLocalTransactionManager.kt:379)
…ns.ThreadLocalTransactionManagerKt.inTopLevelTransaction(ThreadLocalTransactionManager.kt:370)
…ons.ThreadLocalTransactionManagerKt$transaction$1.invoke(ThreadLocalTransactionManager.kt:279)
…ransactionManagerKt.keepAndRestoreTransactionRefAfterRun(ThreadLocalTransactionManager.kt:379)
…transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:249)
…ions.ThreadLocalTransactionManagerKt.transaction$default(ThreadLocalTransactionManager.kt:244)
As the transaction I’m opening doesn’t specify readOnly = true
I don’t understand why I eventually get these errors.
The datasource that i’m using is Hikari (v5.1.0) and i have the configs :
dataSource.apply {
addDataSourceProperty("cachePrepStmts", true)
addDataSourceProperty("prepStmtCacheSize", 250)
addDataSourceProperty("prepStmtCacheSqlLimit", 248)
addDataSourceProperty("useServerPrepStmts", true)
addDataSourceProperty("useLocalSessionState", true)
addDataSourceProperty("cacheResultSetMetadata", true)
addDataSourceProperty("cacheServerConfiguration", true)
addDataSourceProperty("elideSetAutoCommits", true)
addDataSourceProperty("maintainTimeStats", false)
}
Has anyone had a similar problem?