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

Translate PostgreSQL code 21000 (cardinality_violation) #26276

Closed
OrangeDog opened this issue Dec 15, 2020 · 2 comments
Closed

Translate PostgreSQL code 21000 (cardinality_violation) #26276

OrangeDog opened this issue Dec 15, 2020 · 2 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Milestone

Comments

@OrangeDog
Copy link

If duplicate keys are used in a single upsert (ON CONFLICT DO UPDATE) statement, then postgres returns a cardinality violation error.

There are some options to translate it:

  • UncategorizedSQLException (current)
  • DuplicateKeyException
  • DataIntegrityViolationException
  • a new CardinalityViolationException somewhere in the inheritance tree

I'm currently overriding sql-error-codes.xml in order to return a DuplicateKeyException, as the user cause and exception handling are the same.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 15, 2020
@jhoeller jhoeller self-assigned this Dec 15, 2020
@jhoeller jhoeller added in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 15, 2020
@jhoeller jhoeller added this to the 5.3.3 milestone Dec 15, 2020
@jhoeller
Copy link
Contributor

Reading up on it, DuplicateKeyException seems like a good fit indeed. We'll revisit this for 5.3.3, possibly backporting it to 5.2.13.

@jhoeller
Copy link
Contributor

jhoeller commented Dec 17, 2020

Since there is potentially a mismatch with existing duplicate key handling, I've only added this to 5.3.3 for the time being.
There is an easy solution for 5.2.x after all, simply adding the error code to a sql-error-codes.xml file as mentioned above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants