If you have a Domain class with an assigned id (not the default autoincremented long), the id assignment must not be in the constructor, but in a different line.
That means, having this domain:
class State implements Serializable {
String id
static mapping = {
id column: 'id', generator: 'assigned'
}
}
This line doesn't work:
def am = new State(id: 'AM', name: 'Amazonas').save()
But although they seem the same, these three do work:
def am = new State(name: 'Amazonas')
am.id = 'AM'
am.save()
Here are some explanations from the Grails team:
Stumbled upon this and just wanted to let anyone else who might do the same know that this was fixed with the bindable constraint.