micronaut-data
micronaut-data copied to clipboard
Micronaut TX with JOOQ throws NoTransactionException in method without @Transactional when other methods in class use it
Expected Behavior
When using Micronaut's Transaction Management with JOOQ, we should be able to define methods both with and without @Transactional
as in this example controller:
@Controller
public class TestController {
private final DSLContext db;
public TestController(DSLContext db) {
this.db = db;
}
@Transactional
@Get("/foo")
public void foo() {
db.execute("<some query>");
}
// Should still work despite not having @Transactional
@Get("/bar")
public void bar() {
db.execute("<some query>");
}
}
Actual Behaviour
When we mix methods with and without @Transactional
we get the following error when calling the method without it:
io.micronaut.transaction.exceptions.NoTransactionException: No current transaction present. Consider declaring @Transactional on the surrounding method
at io.micronaut.transaction.jdbc.TransactionalConnectionInterceptor.intercept(TransactionalConnectionInterceptor.java:65)
// omitted
Caused by: io.micronaut.transaction.jdbc.exceptions.CannotGetJdbcConnectionException: No current JDBC Connection found. Consider wrapping this call in transactional boundaries.
at io.micronaut.transaction.jdbc.DataSourceUtils.doGetConnection(DataSourceUtils.java:135)
at io.micronaut.transaction.jdbc.DataSourceUtils.getConnection(DataSourceUtils.java:93)
As commented here by @dstepanov:
[...] the Jooq is injection the data source where
getConnection
is delegating toTransactionalConnectionInterceptor
which is failing on the same problem. SpringTX is actually checking if the transaction is missing and returns a simple connection.
Steps To Reproduce
- Checkout example application
- Run
gradle test --info
- Compare with
spring-tx
branch, where test succeeds
Environment Information
No response
Example Application
https://github.com/matt-snider/micronaut-tx-issues
Version
3
@dstepanov Any thoughts on this one? From your comment it sounded like you had some idea of how this could be fixed. I could take a look if you point me in the right direction