Thank you Evgenij,
> H2 doesn't return names of constrains in these exceptions
No it doesn't but the error message contains name of the constraint, in some cases.
Hibernate can try to extract names of the constraints from the error messages, for example:
1) Unique index or primary key violation: "PUBLIC.ACCOUNTS_BY_USERNAME ON PUBLIC.ACCOUNTS(USERNAME) VALUES 1";...
2) Unique index or primary key violation: "PUBLIC.ACCOUNTS_BY_USERNAME_INDEX_A ON PUBLIC.ACCOUNTS(USERNAME)...
3) Unique index or primary key violation: "PRIMARY KEY ON PUBLIC.ACCOUNTS(ID) [1, 'foo']"; SQL statement:...
In case 1, my fix works perfectly and ConstraintViolationException.getConstraintName() returns "ACCOUNTS_BY_USERNAME".
In case 2, H2 Database added suffix "_INDEX_A" to the constraint name. My fix does the same as case 1 and returns "ACCOUNTS_BY_USERNAME_INDEX_A", hoping the message is fixed someday.
My fix doesn't cover case 3 because the constraint name is not in the error message.
Is there any better way about case 2 and 3?
BR,
Tadashi
2022年12月25日日曜日 19:33:30 UTC+9 Evgenij Ryazanov: