Description
When using Postgres, it is easy to add RETURNING id
to attach the generated ID in the FetchSpec
and extract it.
But when using H2 and Spring R2dbc, there is no built-in RETURNING
support as Postgres.
The Jdbc also includes PrepareStatement.getGeneratedKeys()
to fetch the generated key values. Spring Jdbc also include simple GeneratedKeyHolder
to fetch the generated ID in the insert clause.
Spring Data R2dbc issues also mentioned it has resolved this issue, spring-projects/spring-data-r2dbc#14.
But the raw R2dbc API includes a Statement.returnGeneratedValues
, but it is not adopted in the Spring R2dbc.
I wish there is a general solution for all database. When inserting a record, no need to add database specific RETURNING clause, provide a Spring Jdbc similar KeyHolder
to store the generated keys in the query execution, and easily extract the key from the FetchSpec
.