Duplicate entry exception when editing string primary key


I’m having an issue updating the primary key of my entity. The entity extends BaseStringIdEntity but also has a UUID attribute.

I’m using a combined screen browser/editor generated by Cuba Studio to edit the entity. Whenever I edit a non primary key attribute it works fine but when I try to edit the string id of the entity, I get an exception:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'ec62a5ad4ae7a1a41bbd674018821966' for key 'IDX_MY_ENTITY_UUID_UNQ'

By checking the log I found out that this happens because the record is not updated but rather a new record is being inserted with the same uuid key. Is it a bug or am I missing something ? What can I do to work around this ? Thanks.

Other Info

  • Database MySql 8.0.0
  • Platform v6.9.6 (planning on upgrading to latest soon)
  • Studio v6.10.0

Hi Andrei,

You cannot update a primary key - it’s a fundamental restriction in JPA.
In order to update a record in the database, the framework first reads it by primary key. If you change the key in UI, nothing can be loaded.

1 Like

Bummer. Thanks for clarifying that, Konstantin.