Given:
create table Constrained (
id bigint not null,
count integer not null,
name varchar(255),
primary key (id),
constraint count_name_key unique (count, name)
)
A violation of the unique constraint is reported as:
Unique index or primary key violation: "PUBLIC.COUNT_NAME_KEY_INDEX_2 ON PUBLIC.CONSTRAINED(COUNT NULLS FIRST, NAME NULLS FIRST) VALUES ( /* key:1 */ 69, 'Gavin')"; SQL statement:
insert into Constrained(id,name,count) values (4,'Gavin',69) [23505-224]
But PUBLIC.COUNT_NAME_KEY_INDEX_2 is not the name of the constraint, it's a database-generated name. The name of the constraint is count_name_key.
I saw in another issue here that Hibernate was blamed for not correctly extracting the constraint name from h2 messages, but Hibernate cannot possibly extract the constraint name, because it is not contained in the message.