How to elegantly manage transactions in Spring WebFlux with traditional blocking database framework frameworks, such as JDBC, JPA, and MyBatis?
Some features of Spring Data R2DBC are not very good, so I have to use traditional database frameworks. Although @Transactional annotation can be used in WebFlux now, sometimes it doesn't work in chain calls. There is no way to complete transactions with operators like R2DBC.
Is there any simple way to encapsulate manual transactions to support transactions in Mono chain calls? For example:
Mono<OrderInner> monoFromCallable = Mono.fromCallable(() -> {
orderInnerService.saveTest(new Order("id01"));
return entity;
});
Mono<OrderInner> mono2fromCallable = Mono.fromCallable(() -> {
orderInnerService.saveTest(new Order("id02"));
return entity;
});
//Transactional:
return monoFromCallable
.then(mono2fromCallable)
.as(transactionalOperator::transactional);