You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I upgraded to Spring Boot 2.4 and Spring 5.3 in my Kotlin Web MVC project after seeing:
Support for @transactional suspending functions (Kotlin Coroutines)
This transactional support, though, is not working for me in my project where I'm using jdbcTemplate everywhere. Here's an example
An @Controller suspending endpoint:
@PostMapping("/orders")
suspendfunsaveOrder(@RequestBody orderRequest:OrderRequest): ResponseEntity<Order>{
val order = orderService.saveOrder(orderRequest)
// ...
}
Service:
@Transactional
@Service
OrderServiceImpl():OrderService{
overridesuspendfunorderService(request:OrderRequest): Order{
// a mix of WebClient external service calls and calls to dao's that do coroutine jdbc in the `withContext(Dispatchers.IO)`
}
}
In a simple test, my DB calls are not in the same physical transaction. After looking more closely at at this issue, I will only get the @Transactional support if the determined TransactionManager is an instance of ReactiveTransactionManager
When debugging TransactionAspectSupport.invokeWithinTransaction, I always get back the JdbcTransactionManager. Is it not possible to use declarative transactions in Web MVC with coroutines as I've described? I had assumed this enhancement took to managing the ThreadLocal based reference to the open transaction and added it to the current CoroutineContext but that isn't the case for me.
If it's not possible, then what are the caveats around this @Transactional coroutine support? Must I be using Spring WebFlux? Is there a requirement around the return type?
If there's an enhancement to be made here, I'd be happy to take a stab at it once I better understand what the desired state of this is.
The text was updated successfully, but these errors were encountered:
@sdeleuze whenever you have a chance, could you please provide some clarity here as to what's expected/possible and if there's an enhancement to be made here to allow coroutines to work with @Transactional in the way I've described?
It's hard for me to tell whether I'm encountering a bug, something unsupported, or something not yet supported.
I upgraded to Spring Boot 2.4 and Spring 5.3 in my Kotlin Web MVC project after seeing:
This transactional support, though, is not working for me in my project where I'm using
jdbcTemplate
everywhere. Here's an exampleAn
@Controller
suspending endpoint:Service:
In a simple test, my DB calls are not in the same physical transaction. After looking more closely at at this issue, I will only get the
@Transactional
support if the determinedTransactionManager
is an instance ofReactiveTransactionManager
When debugging
TransactionAspectSupport.invokeWithinTransaction
, I always get back theJdbcTransactionManager
. Is it not possible to use declarative transactions in Web MVC with coroutines as I've described? I had assumed this enhancement took to managing theThreadLocal
based reference to the open transaction and added it to the currentCoroutineContext
but that isn't the case for me.If it's not possible, then what are the caveats around this
@Transactional
coroutine support? Must I be using Spring WebFlux? Is there a requirement around the return type?If there's an enhancement to be made here, I'd be happy to take a stab at it once I better understand what the desired state of this is.
The text was updated successfully, but these errors were encountered: