As per your explanation, setting null to the primary will not insert the new record, also it will not update null to the primary key so resulting in the error, as an object is tied with persistence context
What should be your solution
Scenario 1:
If I found a record
Solution 1:
Try to update the same record with new fields without setting null to the primary key.
Solution 2:
Delete an existing record and insert the new one.
Scenario 2:
If no record found
Solution
: Insert new record directly as you mentioned.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…