Violation Constraint PRIMARY KEY Message

Hi there,
can I customize the SqlServerException message when I have a violation error for duplication of Primary Key constraint after the creation of a new instance of an entity in the EDIT screen?

Thanks in advance.

Hi,

Look at the cuba.uniqueConstraintViolationPattern property description - it defines a regular expression that is used by the exception handler that catches the unique constraint violations.

You may need to adjust this expression to your DBMS, and the value of its first non-empty group is used to find a message to the user in the main message pack.

So for example if you got this notification:

Then with the default regexp and adding

DEMO_FOO_PKEY = An entity with this ID already exists

to the main message pack, you will get the following notification:

You can also completely replace the standard UniqueConstraintViolationHandler by providing your own exception handler with order HIGHEST_PLATFORM_PRECEDENCE - 10.

1 Like