I was trying to apply a date range uniqueness constraint, I am using Postgres so i used a postgres exclsuion constraint, and i defined a custom message for the index in the messages.properties under the Web module -like other unique indexes i have custom messages for-, but unfortunately it’s not showing in the error that gets displayed, the constraint is defined as:
ALTER TABLE VP_WORK_SCHEDULE
ADD CONSTRAINT IDX_VP_WORK_SCHEDULE_UNQ
EXCLUDE USING gist
( COUNTRY_ID WITH =,
COALESCE(SECTOR_ID, ‘00000000-0000-0000-0000-000000000000’) WITH =,
daterange(START_DATE, COALESCE(END_DATE, ‘infinity’), ‘[]’) WITH &&
);
Thanks for your reply, I have defined the cuba.uniqueConstraintViolationPattern property. but I am not sure that’s the problem as the other normal unique constraints have custom messages defined for them in the main message pack and displayed correctly. I think the problem lies in that the framework doesn’t recognize the constraint created as
ALTER TABLE VP_WORK_SCHEDULE
ADD CONSTRAINT IDX_VP_WORK_SCHEDULE_UNQ
EXCLUDE USING gist
( COUNTRY_ID WITH =,
COALESCE(SECTOR_ID, ‘00000000-0000-0000-0000-000000000000’) WITH =,
daterange(START_DATE, COALESCE(END_DATE, ‘infinity’), ‘[]’) WITH &&
);
as a unique constraint. as technically it’s not a unique constraint but an exclusion constraint.
What message have you defined? The standard one considers only unique constraints: ERROR: duplicate key value violates unique constraint "(.+)"
Modify the pattern to cover exclude constraints, too.
I already defined the following entry in both app.properties and web-app.properties:
cuba.uniqueConstraintViolationPattern = ERROR: duplicate key value violates unique constraint “(.+)”
but the exclusion constraint is not showing this error message, although other normal unique constraints are displaying the custom error message when violated.
That’s what I’m talking about: you’ve defined the custom message for the unique constraint only. Modify it to add the exclusion constraint, too. (By the way, the standard PostreSQL message for it is ERROR: conflicting key value violates exclusion constraint).
HI,
If you want to specify separate messages for Exclude and Unique constraint violations you can extend UniqueConstraintViolationHandler and implement any logic you want there.