I need to use optimistic locking for my record. But also in our system, we use mapping logic between layers, records to POJO, and vice versa. And if I use store() on new records it works, but I want to store() like update statement on the existing record, but when I convert it from POJO, it works like for new record and I got duplicate id exception.
A know that I can save records with context.update(), but I need optimistic locking and as I know it works only with UpdatableRecords (store() method). In the documentation I found :
`When loading records from POJOs, jOOQ will assume the record is a new record. It will hence attempt to INSERT it.
and it means that I can't update existing records from POJO with method store() and should use the update from context, but it can't work with the optimistic lock.
Hence, is there any chance to get it at the same time optimistic lock and work with POJOs?
UPDATE : Thx Lucas. I've started using record.update(), but I ran into another problem :
UserRecord userRecord = context.fetchOne(...);
UserPojo userPojo = mapper.toPojo(userRecord);
userPojo.setName("new_name")
UserRecord userRecordForSave = context.newRecord(USER,userPojo);
userRecordForSave.update()
got DataChangedException
But I turned on optimistic locking and inner JOOQ method checkIfChanged() - validate originals[] fields, but I don't have them after mapping POJO to record, hence I got DataChangedException: Database record has been changed. What is the correct method of mapping POJO in this case?