'Spring reactive @Transactional not working
I don't understand why @Transactional doesn't work in reactive. After saving to the repository, I throw an error. But the data still appears in the database. Spring v 5.3.10
My controller
@GetMapping("/test/save")
fun saveListNotification(): Flux<Notification> {
return service.saveListNotification(listOf(
...
))
}
My service
@Transactional
fun saveListNotification(listOf: List<Notification>): Flux<Notification> {
return Flux.fromIterable(listOf)
.flatMap { notificationRepository.save(it) }
.doOnNext {
if (it.rawJsonHash.equals("4")) throw Exception()
}
}
My repository
interface NotificationRepository : ReactiveCrudRepository<Notification?, UUID?>
Solution 1:[1]
I solved my problem change on the @Transactional(rollbackFor = [Exception::class]) Because @Transactional default will be rolling back on RuntimeException and Error
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | GRbI3yH |
