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
Conflict on insert gets translated to DataIntegrityViolationException instead of DuplicateKeyException in Spring 6 #29699
Comments
I suppose this is coming from MySQL/MariaDB, MS SQL and Oracle, as per your comment on the other issue? 23000 is a general constraint violation error. I suspected that Oracle might report that SQL state already, with its old error code 1 attached. But for MySQL, I thought I saw it supporting 23505 but must have mis-read that. MariaDB inherited that legacy from MySQL, I suppose. All of them really should be reporting 23505 instead, there is an old enhancement request for MySQL for it that never got addressed. Anyway, it would be helpful to analyze the exact exception reported by the JDBC driver for those cases, ideally with exception class, SQL state, error code and exception message. If you have the chance to check the remaining databases for those exception details, that would be super helpful. We'll try to integrate corresponding detection rules then since those databases are unlikely to fix their SQL state. |
Hi,
Postgres, H2, HSQL, DB2 look good (return 23505) |
Thanks, @lukas-krecan! I've got a change ready that specifically looks at those error codes within SQL state 23000, along the following lines:
As far as I was able to find out, those error codes are vendor-specific but documented at least, and not overlapping with error codes in other affected databases - in particular not within SQL state 23000. From that perspective, the above is a pragmatic solution for the time being, within a specific SQL state condition - and still avoiding database production name detection and the parsing of an error codes mapping file, so still a significant improvement over using To be committed tomorrow. |
…g-projects#29748) There was a typo in the test, covering the wrong SQLState code. Polishes a644245. Relates to spring-projectsgh-29699.
Followup from #29511
If there is primary key conflict on insert, Spring 6.0.3 returns
DataIntegrityViolationException
instead ofDuplicateKeyException
as it did in Spring 5. It would make sense to me to implement similar fix as you did for #29511. The SQL state seems to be 23000.The text was updated successfully, but these errors were encountered: