Skip to content

Default ID value on new record is inserted when optimistic locking is enabled #557

@jnfeinstein

Description

@jnfeinstein

I believe the issue occurs here. The version is incremented prior to deciding if the ID should be included. This results in the record being considered not new for purposes of including the ID.

CREATE TABLE account (
    id SERIAL PRIMARY KEY,
    name TEXT NOT NULL,
    version INTEGER NOT NULL
);
@Table
data class Account(
    @Id var id: Long = 0L,
    var name: String = "",
    @Version val version: Long = 0L,
)
org.springframework.dao.DataIntegrityViolationException: executeMany; SQL [INSERT INTO account (id, name, version) VALUES ($1, $2, $3)]; duplicate key value violates unique constraint "account_pkey"; nested exception is io.r2dbc.postgresql.ExceptionFactory$PostgresqlDataIntegrityViolationException: [23505] duplicate key value violates unique constraint "account_pkey"

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions