-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transaction rollback does not work when using jOOQ #849
Comments
This doesn't seem related to Spring Data because of missing context propagation. |
@mp911de jOOQ 3.20 has introduced a way to inject context (e.g. reactor context) into jOOQ's reactive streams support (R2DBC or JDBC backed):
Do you think it would be possible now, to propagate Spring transaction information to jOOQ? I've tried to reverse engineer what Spring is doing here, and couldn't access the relevant information through any public API: I'll try tackling this again eventually, but if you have pointers, I'd be very glad. Perhaps, this could be solved with yet another SPI that extracts the (transaction aware) R2DBC |
Thanks a lot for spending time here. Spring Framework binds transactional resources to the context using a mutable Transaction Holder. This is to enable nested transactionality handling and the actual resource management is initiated with That being said, there's a lot of Spring-specific classes involved that hold stacks, maps-of-maps and strangely looking map associations if you look at it during runtime. If you want to participate in a Spring-managed transaction, that could be by users using Let me know whether that helps (or if it adds to confusion) and if I can provide more details. |
@mp911de Thanks, I found most of those classes as well during my reverse engineering session. I guess I'll just have to try again. I might eventually find the solution. I guess the solution would have to be implemented in Spring Boot's jOOQ starter, which is the only place that knows both jOOQ and Spring Data, and is thus allowed to depend on both. I can try to contribute it, once I'm sure how it should work. (I'm aware of this limitation: spring-projects/spring-boot#44372, though that isn't forever). |
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: jOOQ/jOOQ#16109
Steps to reproduce the problem
DemoRepository
DemoService
and then
repo.getAll() // returns ["a"] instead of []
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
The text was updated successfully, but these errors were encountered: