Juergen Zimmermann
Juergen Zimmermann

Reputation: 2222

How to map a 1:1 relationship with Spring Data R2DBC?

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.

Upvotes: 7

Views: 10101

Answers (2)

Dmitry Avgustis
Dmitry Avgustis

Reputation: 1131

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

Upvotes: 1

tburzynski
tburzynski

Reputation: 104

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

Upvotes: 8

Related Questions