Skip to content
Advertisement

How to implement ManyToMany in r2dbc

R2DBC does not support composite keys currently. I wonder how we may implement a many-to-many relationship for now?

For example, given the two entities:

JavaScript

and their schemas:

JavaScript

I can create a table for the many-to-many mapping:

JavaScript

But how should we define the mapping class ItemTag in kotlin/java?

JavaScript

Or is it fine to omit the @Id? Then there cannot be any Repository for the class? I guess that would be fine. Is this the only implication?

Advertisement

Answer

There might be other ways to do this. Since CompositeKey is not supported yet in R2DBC I think. Hence, this is just one way to resolve your problem.

Data class

JavaScript

Then Repository

JavaScript

Repostory Impl

JavaScript

Something like that.

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