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?>
CodePudding user response:
I solved my problem change on the @Transactional(rollbackFor = [Exception::class]) Because @Transactional default will be rolling back on RuntimeException and Error