4

I am trying to find whether there is any support for identifier generation support we can use with R2DBC.

Similar to @GeneratedValue provided by hibernate for jdbc.

I know that spring-data-r2dbc doesn't support identifier generation yet.

1 Answers1

0

Currently using Spring R2dbc and Spring Data R2dbc there is no such an annotation for setting sequence generation for the primary key. The id value setting completely depends on the db itself. You can set it manually or using the database built-in id generation strategy.

There is an example using sequence in Postgres.


CREATE TABLE order_details(
    order_id SERIAL,
    item_id INT NOT NULL,
    item_text VARCHAR NOT NULL,
    price DEC(10,2) NOT NULL,
    PRIMARY KEY(order_id, item_id)
);

CREATE SEQUENCE order_item_id
START 10
INCREMENT 10
MINVALUE 10
OWNED BY order_details.item_id;

INSERT INTO 
    order_details(order_id, item_id, item_text, price)
VALUES
    (100, nextval('order_item_id'),'DVD Player',100),
    (100, nextval('order_item_id'),'Android TV',550),
    (100, nextval('order_item_id'),'Speaker',250);

More details, please refer: https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-sequences/

Hantsy
  • 8,006
  • 7
  • 64
  • 109