7

I have these simplified tables

CREATE TABLE address(
    id VARCHAR(36) NOT NULL PRIMARY KEY,
    zip VARCHAR(5) NOT NULL,
    city VARCHAR(32) NOT NULL
)
CREATE TABLE customer(
    id VARCHAR(36) NOT NULL PRIMARY KEY,
    name VARCHAR(32) NOT NULL,
    address_fk VARCHAR(36) NOT NULL,
    FOREIGN KEY (address_fk) REFERENCES address(id)
)

and these simplified Kotlin classes:

data class Address(val id: String, val zip: String, val city: String)
data class Kunde(val id: String?, val name: String, val address: Address)

When I use @Column(address_fk) for the property address I get a ConverterNotFoundException that no converter from String to Address was found. Also @MappedCollection instead of @Column doesn't look appropriate. Any hint is appreciated.

Juergen Zimmermann
  • 2,084
  • 7
  • 29
  • 43

2 Answers2

8

Relations are not supported yet in R2DBC https://github.com/spring-projects/spring-data-r2dbc/issues/99

tburzynski
  • 104
  • 1
  • 2
    Thank you. At least now I know that I have to work around, e.g. by submitting 2 queries and do the join be eg `zip`ing the 2 `Mono`s. – Juergen Zimmermann Oct 22 '19 at 14:35
  • 4
    I am facing the same problem. I did "entity transfer object" where I am mapping Entity A to it, then in ETO object I have getters and setters where I can fetch required data from Entity B or Entity C. This solution is like reinventing the wheel but it works. Maybe this will help to solve your problem. – tburzynski Oct 23 '19 at 10:14
  • 2
    May be [lc-spring-data-r2dbc](https://github.com/lecousin/lc-spring-data-r2dbc) can help you ? It implements relationships (except many to many) so it seems easier than having to do it manually. – Zinc Dec 13 '20 at 09:07
  • @MiroslavGlamuzina Why should it be a comment? It is the PERFECT answer for this question as R2DBC does not support. – RamPrakash Jul 03 '22 at 20:02
  • Why does Spring R2DBC which literally stands for Reactive Relational Database Connectivity even exist if it doesn't support relationships ? – duppydodah Jul 25 '23 at 04:00
1

I suggest an alternative solution.

Take a look into Micronaut and Hibernate reactive. It supports all sorts of things we got used to in spring/jpa, like pagination, relations and even JPA-QL custom queries.

All this is done using reactive streams and is non-blocking. (True magic)

More info https://micronaut-projects.github.io/micronaut-data/latest/guide/#hibernateReactive

Dmitry Avgustis
  • 854
  • 1
  • 9
  • 14