BUG Entity with PK 0 not possible to edit

Attached you find a standard Project with the entity Account, Key = id, Integer, defined by user

It is not possible to change the value of the entity with the id = 0 ( Unique constraint violation occurred (PK_ACCOUNT) ).

JMix tries to enter a new record ! I tried the same with JMix 2.2.0, JMix 2.0.0 and get the same problem … Is this a JMix Studio Problem ( as I did not have this problem in the past ! ).

Jmix version: 2.2.1
Jmix Studio plugin version: 2.2.1-233
IntelliJ version: IntelliJ IDEA 2023.3.6 (Ultimate Edition)

CRM20.zip (101.5 KB)

Hi,
I checked this solution. So, analysis right below:

  1. What’s a point to change ID of entity? If you would like to sort/count entity better solution is to add sequence field and increase it.
  2. All our code based on idea of immutability of PK. There is strange point to edit PK.
  3. BTW this is problem(not a bug). I create the issue to fix this problem. Here you can monitor the progress. But I do not guarantee that the incident with this error will be fixed.

Regards,
Dmitry

Hi

I fully agree with you about changing PK.

I don’t want to change the PK. I just try to edit the content of the entity ( description ) and JMIX decides, this is a new entity. This happens only when the PK has the int value 0. This entity is existing.

Regards
Felix

Hello. Try to add this annotation @PrimaryKey(validation = IdValidation.NONE) to the entity with integer primary key.

https://eclipse.dev/eclipselink/documentation/2.4/jpa/extensions/a_primarykey.htm

By default, EclipseLink interprets zero as null for primitive types that cannot be null (such as int and long), causing zero to be an invalid value for primary keys.

3 Likes

Thank you a lot. This did solve that problem !

@Jmix; is this an option to include it in the entity java class generation ?

@yuribakunx, thank you for the solution!

We’ll consider it. Created issue: Enable zero as integer PK value · Issue #3104 · jmix-framework/jmix