Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation for "Primary key already exists" #36

Open
javier-godoy opened this issue Jul 27, 2021 · 2 comments
Open

Add validation for "Primary key already exists" #36

javier-godoy opened this issue Jul 27, 2021 · 2 comments
Labels
enhancement New feature or request needs-triage

Comments

@javier-godoy
Copy link
Member

When the entity id is not automatically generated, it's possible that an insert will trigger a primary key violation. That's a pretty common case, and a custom validator would be needed in order to avoid reporting it as an "unknown error".

Should we provide some support for this scenario in commons-backend? (either as an ad-hoc validator, or as some exception postprocessing.)

@javier-godoy javier-godoy added the enhancement New feature or request label Jul 27, 2021
@ngonzalezpazFC
Copy link
Contributor

Detecting this while trying to save an existing ID could be useful to force the user to use the right method (save or update) for the action that he's trying to do, because if you use save with an existing ID, the entity will be updated. Maybe the user tried to persist a new entity but ended up updating an existing one, without noticing it.

@mlopezFC
Copy link
Member

I'm not sure if Commons Backend should do something in this scenario. Whether the entity id is automatically generated or not is a JPA mapping decision. Implementing this would require to "configure" the library in a "automatically generated id" mode so the validation is useful or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs-triage
Projects
None yet
Development

No branches or pull requests

4 participants