Error when trying to modify entity with id=0

In the project I’m working, I have an entity with an Integer id, assigned by user, which happens to be 0. When I edit this entity, I get an optimistic lock error, but I don’t get this error when I change the id to anything else. When I try to reproduce this in a new project, I get a Unique constraint violation exception instead of Optimistic lock: Internal Exception: java.sql.SQLIntegrityConstraintViolationException: integrity constraint violation: unique constraint or index violation ; PK_ENTITY_1 table: ENTITY_1 Error Code: -104 Call: INSERT INTO ENTITY_1 (ID, NAME) VALUES (?, ?) bind => [0, TEST_1] Query: InsertObjectQuery(com.company.entityid0.entity.Entity1-0 [managed])

It looks as if it’s trying to insert instead of update, for some reason. When I create a new entity with id 1, it works as expected.

Steps to reproduce:

  • 1: Create a new JPA entity with Integer id assigned by user and any other field.
  • 2: Create a new instance of this entity, setting the id to 0, and save it.
  • 3: Try to change the other field and save.

Jmix version: 2.2.0
Jmix Studio plugin version: 2.2.0-233
IntelliJ version: IntelliJ IDEA 2023.3.5 (Community Edition)