On constraint violation from the DB, the ConstraintViolationException thrown by SQLStateConversionDelegate on code 23505 code, is not mapped with ConstraintType.UNIQUE but rather mapped with the default ConstraintType.OTHER .
The error code table from Postgres states that 23505 code is a unique constraint violation.
Workaround:
Compare SQLState code instead of the ConstraintType.
While not that big of an issue, I think it is a nicer option than enumerating all the possible codes when the kind type is there and working with other DBs (at least from simple search on other implementing delegate implementations)
Platform description:
Running Quarkus 3.17.3 application with Hibernate 6.6.3 and PostgreSQL.
It seems that 23, 27 and 44 are all mapped to ConstraintViolationException but only 23505 is actually a violation of type UNIQUE. There are other types under class 23, but it seems that only 23505 should be mapped to ConstraintType.UNIQUE, while OTHER kinda catches all the rest since there is no clear distinction what kind is supposed to be
Link to original message on Zulip
Problem description:
On constraint violation from the DB, the ConstraintViolationException thrown by
SQLStateConversionDelegate
on code23505
code, is not mapped withConstraintType.UNIQUE
but rather mapped with the defaultConstraintType.OTHER
.The error code table from Postgres states that 23505 code is a unique constraint violation.
Workaround:
Compare SQLState code instead of the ConstraintType.
While not that big of an issue, I think it is a nicer option than enumerating all the possible codes when the kind type is there and working with other DBs (at least from simple search on other implementing delegate implementations)
Platform description:
Running Quarkus 3.17.3 application with Hibernate 6.6.3 and PostgreSQL.