Jooq save or update method returns an error

Viewed 138

i'm trying to implement save or update method using jooq and table with unique constraint "phone_number_key"
My code:

var insertStep = dslContext.insertInto(Users.USERS)
        .set(Users.USERS.FIRSTNAME, user.getFirstname())
        .set(Users.USERS.PHONENUMBER, user.getPhoneNumber())
        .onConflict()
        .doUpdate()
        .set(Users.USERS.FIRSTNAME, user.getFirstname())
        .returningResult(Users.USERS.ID);
var record = insertStep.fetchOne();

but i got exception

ERROR: duplicate key value violates unique constraint "phone_number_key" Detail: Key ("phoneNumber")=(+999999999) already exists.

I got same error with ".onDuplicateKeyUpdate()" method
I use postgres db
What am i doing wrong ?

1 Answers

got it work with

.onConflict(Users.USERS.PHONENUMBER)
.doUpdate()
.set(Users.USERS.FIRSTNAME, user.getFirstname())
Related