PurposeConstrains a property as unique at the database level
username unique: true
trueif the property must be unique. This is a persistent call and will query the database.
It is possible (though unlikely in practice) for uniqueness validation to pass but for the subsequent save to fail. If another save or update happens to update the database between the Grails check and the actual save of your instance, the call will fail. The only way to prevent this would be to use a transaction at theYou can also define multi-column
SERIALIZABLEisolation level, but this is very bad for performance.
uniqueconstraints by declaring the other field(s) to be included as the parameter value. If there is one other field, specify its name, but if there are more than one use a List, for example:Example:
In this example the
group unique: 'department'
groupname must be unique in one
departmentbut there might be groups with same name in different departments, i.e. the group name isn't unique by itself.Another example:
In this example
username(unique: ['group', 'department'])
loginmust be unique in
department. There might be same logins in different groups or different departments.This constraint influences schema generation.Error Code: