Provide support to increase developer productivity in Java when using Reactive Relational Database Connectivity. Uses familiar Spring concepts such as a DatabaseClient for core API usage and lightweight repository style data access.
Apache License 2.0
708
stars
132
forks
source link
Transaction rollback does not work when using jOOQ #849
When an exception is thrown within a transaction, jOOQ should rollback the whole transaction
Actual behavior
When an exception is thrown within a transaction, jOOQ does not rollback the whole transaction. The inserts before the exception are committed to the database.
suspend fun insert(id: String) {
if (id == "b") {
throw RuntimeException("error while inserting")
}
db.insertInto(DEMO_TABLE)
.set(DEMO_TABLE.ID, id)
.awaitSingle()
}
DemoService
suspend fun addRecords(): Unit = transactionalOperator.executeAndAwait {
log.info("Inserting records")
repo.insert("a")
repo.insert("b") // throws error
}
Even-though the inserts are done within a transaction, it does not seem to be rolled back when an exception is thrown
Logs:
Executing query: BEGIN READ WRITE
Executing query: insert into demo_table (id) values ($1)
Executing query: ROLLBACK
Executing query: select demo_table.id from demo_table
When swapping jOOQ DSLContext to DatabaseClient the rollback works 🤔
suspend fun insert(id: String) {
if (id == "b") {
throw RuntimeException("error while inserting")
}
dbClient.sql("insert into demo_table (id) values ('$id')")
.fetch()
.awaitSingle()
}
Checking debug logs, found a difference after the insert statement was executed:
Expected behavior
When an exception is thrown within a transaction, jOOQ should rollback the whole transaction
Actual behavior
When an exception is thrown within a transaction, jOOQ does not rollback the whole transaction. The inserts before the exception are committed to the database.
Issue on jOOQ: https://github.com/jOOQ/jOOQ/issues/16109
Steps to reproduce the problem
DemoRepository
DemoService
and then
Full code: https://github.com/linktosriram/r2dbc-jooq-rollback
Even-though the inserts are done within a transaction, it does not seem to be rolled back when an exception is thrown
Logs:
When swapping jOOQ
DSLContext
toDatabaseClient
the rollback works 🤔Checking debug logs, found a difference after the insert statement was executed:
Using
DatabaseClient
Using
DSLContext
The
transactionStatus
is different when usingjOOQ
. Not sure if that's the reasonjOOQ Version
3.18.7
Database product and version
PostgreSQL 15.5
Java Version
OpenJDK Runtime Environment Corretto-21.0.1.12.1
OS Version
macOS Ventura 13.0
JDBC driver name and version (include name if unofficial driver)
org.postgresql:r2dbc-postgresql:1.0.3.RELEASE