Handling Unique Constraint Violation Exceptions
Jmix 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 message bundle. Message key should have a
databaseUniqueConstraintViolation prefix plus the database unique index name in uppercase. For example:
So, the default notification looks like this:
After you add a custom message key, you will get the following notification:
Detection of database constraint violation errors is done by the
UniqueConstraintViolationHandler class which determines the exception type by searching a special marker string in the messages of all exceptions in the chain.
You can also completely replace the standard handler by providing your own exception handler with a higher precedence, for example,
@Order(JmixOrder.HIGHEST_PRECEDENCE - 10).