Search code examples
exceptiongrailsuniquemessagegrails-orm

Set message for unique contraint violation in Grails


In Grails,

When an specific 'unique' constraint is violated, I want to set the message of the Exception that rises.

Is that possible?


Solution

  • The message code to use for each constraint is listed in the reference page for that constraint, e.g. http://grails.org/doc/latest/ref/Constraints/unique.html. From that it looks like the code you need is

    com.project.ModelName.fieldName.unique=blah 
    

    You need to replace com.project.ModelName.fileName with your appropriate value

    Thanks to http://grails.1312388.n4.nabble.com/Custom-error-message-in-message-properties-td3335696.html