Skip to content
Advertisement

Obtaining a nested objects using Spring Data R2DBC

I’m new to Project Reactor and R2DBC. How to receive and merge Flux<Child> with Mono<Parent> properly using Spring Data R2DBC reactive repositories?

Parent:

JavaScript

ParentRepository:

JavaScript

Child:

JavaScript

ChildRepository:

JavaScript

ParentPersistenceAdapter:

JavaScript

My solution is:

JavaScript

Advertisement

Answer

Assuming the existence of a withChildren(Flux<Child> children) type method, you can just do:

JavaScript

However, this is a bit odd – you wouldn’t usually have a Flux on a DAO like that as you’d need to subscribe to it and manage the content separately. You’d more normally have a List<Child> instead. For that situation, you can collect the child stream as a list, zip() the corresponding Mono publishers together, then combine them into your final Parent object.

So assuming a withChildren(List<Child> children) method:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement