hi there, I'm trying to use the kotlin-coroutines ...
# spring
v
hi there, I'm trying to use the kotlin-coroutines with Spring Boot, and everything seems to work nice util I add the
@Transactional
annotation to one of my spring service's method. After the annotation is added some classCastException is thrown, see the details here: https://stackoverflow.com/questions/65331458/classcastexception-monoonerrorresume-cannot-be-cast-to-class-io-ebean-query Is there a howto on how to use the kotlin-coroutines with spring transactions? thanks,
s
Hi, which version of Spring Boot ? Are you using
spring-boot-starter-web
or
spring-boot-starter-webflux
?
v
• spring-boot: 2.4.0 • kotlin: 1.4.21 Aaaand I'm using the
com.vaadin:vaadin-spring-boot-starter
dependency, 'cause at the end the app is a Vaadin-based app.
s
I think i fixed that in Boot 2.4.1
❤️ 1
v
I'm using this as an example to use the coroutines in Vaadin Routes: https://github.com/mvysny/vaadin-coroutines-demo/blob/master/src/main/kotlin/org/test/MainRoute.kt
s
So please upgrade.
v
give me a moment, and I'll try it 🙂
s
But usually that means you try to use Coroutines/Reactive transaction with regular persistence which is not supported.
So if you use Coroutines +
@Transactional
you should use Spring Data R2DBC or Spring Data Reactive NoSQL support with Coroutines extensions.
v
oooookay. even if the transaction is started in the coroutine and ended in the same coroutine as well?
nice, it seems to work after the spring update. let me turn on the verbose logging to double-check, but thanks for quick the help
s
Even in that case yeah, if you are using Coroutines + transactions with non Reactive transaction manager I think transactions will simply not being used.
Instead of the error you had before.
v
okay, that's not so nice, and based on the verbose logging you're right.
I'm trying to use the ORM called EBean - which I know, and IMHO 1 new thing is enough to learn in a pet project 🙂 is there a Reactive ORM in case I'll change my mind, and learn multiple new tools with this project?
s
You should probably use it with Spring MVC and non suspending endpoints. Spring Data R2DBC is not a full fledge Reactive ORM but probably your best option.