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:
@Table
class Item(
@Id var id: Long?,
var title: String,
var description: String,
)
@Table
class Tag(
@Id
var id: Long?,
var title: String,
var color: String,
)
and their schemas:
CREATE TABLE item (
id SERIAL PRIMARY KEY NOT NULL,
title varchar(100) NOT NULL,
description varchar(500) NOT NULL
);
CREATE TABLE tag (
id SERIAL PRIMARY KEY NOT NULL,
title varchar(100) NOT NULL,
color varchar(6) NOT NULL
);
I can create a table for the many-to-many mapping:
CREATE TABLE item_tag (
item_id bigint NOT NULL,
tag_id bigint NOT NULL,
PRIMARY KEY(item_id, tag_id)
);
But how should we define the mapping class ItemTag
in kotlin/java?
@Table
class ItemTag(
// ??????????????????????? @Id ?????????????????????
var itemId: Long,
var tagId: Long,
)
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?