Problems with primary key of type String SQL Server

These problems are happening:

  • The system is trying to convert String to Integer and the field is String
  • Create a new record where the primary key is a String save then try to edit and change the value of the primary key and save again. The system will not update the record, it will create a new one, why is this happening? if I cannot edit the value of a primary key of type String, why does the system let me edit this field when I click edit?

See the attached video

Thank you

screen-capture.7z (10.2 MB)

Hi,

Create a new record where the primary key is a String save then try to edit and change the value of the primary key and save again. The system will not update the record, it will create a new one, why is this happening?

It is normal behavior that when the identifier is changed, a new record is created. JPA ORM doesn’t take into account PK changes.

if I cannot edit the value of a primary key of type String, why does the system let me edit this field when I click edit?

When creating a string entity, you must specify an identifier. The platform will not be able to generate it automatically for the String data type, so the screen contains an editable ID field. You can always prevent field editing for existing entities in the screen controller.

The system is trying to convert String to Integer and the field is String

Could you provide a sample project that reproduces the problem?

Thank you
Andrey Subbotin

Hello,

You can download my project here
https://drive.google.com/file/d/1MS1rpU3r_72gtk2SiHhic-u78Jmk7UKU/view?usp=sharing

There is the project and the backup of my database just follow the same steps that I showed in the video and you will see the error

Thank you.

1 Like

Hi,
The problem relates to the view Cep_View with the ID integer column.
ID column is calculated as: isnull(cast(ltrim(rtrim(upper(a.cep))) as int),0).
MSSQL can’t cast 01001000-XXX string value to integer value and throws an error:
Conversion failed when converting the varchar value ‘01001000-XXX’ to data type int.

1 Like

You’re right, the problem was the view ID field
thank you