-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Jooq DSL.using seems to ignore TransactionAwareConnectionFactoryProxy #13378
Comments
Thanks for your report. Are you sure you're supposed to create the proxy yourself? It seems like something you should rather have Spring inject into your application, instead. |
Another curious thing that is clearly different between your two approaches: You're never closing your explicitly created connection... |
I created it explicitly here to try to isolate a minimal case, but yes, the idea would be to either declare the bean elsewhere or let Spring create it. I was facing the same issue when the bean was injected from elsewhere though? You're right I should close the connection in the case where I create it explicitly, thanks for catching it ! |
Makes sense, just trying to think what causes the difference and if it's really jOOQ related.
So, what happens then? Will your calls still share the same transaction? |
I added a close() call on the connection, but the output stays similar : fun main(args: Array<String>) {
runApplication<SpringBootApp>(*args) {
}
}
@SpringBootApplication
class SpringBootApp
@Configuration
class CommandLineRunner(
@Autowired private val transactionalOperator: TransactionalOperator,
@Autowired private val connectionFactory: ConnectionFactory
) : CommandLineRunner {
override fun run(vararg args: String?) {
runBlocking {
getTxIdFromDBTransactional()
getTxIdFromDBTransactional()
}
}
private suspend fun getTxIdFromDBTransactional() =
transactionalOperator.executeAndAwait {
println("With direct connection from TransactionAwareConnectionFactoryProxy = all calls happen in same tx: " + getTxIdJooqDirectConnection())
println("With direct connection from TransactionAwareConnectionFactoryProxy = all calls happen in same tx: " + getTxIdJooqDirectConnection())
println("With direct connection from TransactionAwareConnectionFactoryProxy = all calls happen in same tx: " + getTxIdJooqDirectConnection())
println("It doesn't seem to be when we use TransactionAwareConnectionFactoryProxy: " + getTxIdJooqConnectionFactory())
println("It doesn't seem to be when we use TransactionAwareConnectionFactoryProxy: " + getTxIdJooqConnectionFactory())
println("It doesn't seem to be when we use TransactionAwareConnectionFactoryProxy: " + getTxIdJooqConnectionFactory())
}
private suspend fun getTxIdJooqDirectConnection(): Int {
val reactiveConn = TransactionAwareConnectionFactoryProxy(connectionFactory).create().awaitSingle()
val res = DSL.using(
reactiveConn
).dsl()
.select(DSL.function("txid_current", SQLDataType.INTEGER))
.fetchOneAwait()
.value1()
reactiveConn.close()
return res
}
private suspend fun getTxIdJooqConnectionFactory(): Int =
DSL.using(
DefaultConfiguration()
.set(TransactionAwareConnectionFactoryProxy(connectionFactory))
.set(SQLDialect.POSTGRES)
).dsl()
.select(DSL.function("txid_current", SQLDataType.INTEGER))
.fetchOneAwait()
.value1()
suspend fun <T : Record> ResultQuery<T>.fetchOneAwait(): T =
Mono.from(this).awaitSingle()
} Output :
|
|
I added an awaitSingle() on the Publisher of close and apparently the connection is already closed at that point :
|
Wow, well who is closing it, then? jOOQ shouldn't be closing it... I can have a closer look, if you could share the complete reproducer project? We have a template for that: https://github.com/jOOQ/jOOQ-mcve, but any format is fine... |
Hey, guys. After some debugging, I came to the conclusion that this is a problem in This is my workaround, if that would be of help to anyone: |
I'm closing this issue since it seems to be about a specific Spring configuration and setup, not about a bug in jOOQ. |
Hi,
(coming from spring-projects/spring-boot#24049)
Expected behavior
=> Should happen in transactions like when we pass a connection to Jooq directly from this factory
Actual behavior
Absence of transaction awareness
Steps to reproduce the problem
Output :
Versions
Regards,
The text was updated successfully, but these errors were encountered: