3.2.12.3.1. Handling Unique Constraint Violation Exceptions
The framework allows you to customize the message displayed by an exception handler for a database constraint violation error.
A custom message should be specified in the main message pack of the web
module with a key equal to the database unique index name in uppercase. For example:
IDX_SEC_USER_UNIQ_LOGIN = A user with the same login already exists
So, for example, if you got this notification:
then by adding
IDX_DEMO_PRODUCT_UNIQ_NAME = A product with this name already exists
to the main message pack, you will get the following notification:
Detection of database constraint violation errors is done by the UniqueConstraintViolationHandler
class which uses regular expressions depending on your database type. If the default expression doesn’t recognize errors from your database, try to adjust it using the cuba.uniqueConstraintViolationPattern application property.
You can also completely replace the standard handler by providing your own exception handler with a higher precedence, e.g. @Order(HIGHEST_PLATFORM_PRECEDENCE - 10)
.