Map ConstraintType to UNIQUE on ConstraintViolationException

Description

Link to original message on Zulip

Problem description:

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.

relates to

Activity

Show:

Gavin King 3 hours ago

Fixed along with many other similar issues as part of work on https://hibernate.atlassian.net/browse/HHH-19300.

Royi Freifeld January 2, 2025 at 1:30 PM

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

Fixed

Details

Assignee

Reporter

Fix versions

Priority

Created January 2, 2025 at 11:01 AM
Updated 3 hours ago
Resolved 3 hours ago