Why not use a sequence? You can use a sequence that is global for all your domain classes, or you can define a specific sequence for that domain. You can do something like this:
static mapping = { id generator: 'sequence', params: [sequence: 'some_name_sequence'] }
.. and if for some reason you still need to have nextId, you can create a get method that returns an id value, something like:
def getNextId() { return id }
If you do this, you will need to define nextId as a transition value.
This, of course, assumes that you do not need id, and nextId is different.
source share