0
votes

I have a MySQL table with the ID attribute as autoincremental and I need that, when doing an insert from Grails, the value of the id is auto-completed increasing.

My grails class has the following mapping:

static mapping = {
     id column: "id", type: "long", sqlType: "int", generator: 'assigned'
     datasource 'dialer'
     version false
     }

But wanting to make an insert gives me the following error:

Message: ids for this class must be manually assigned before calling save ()

Would they give me a hand? Thank you!

2
grails id auto increments without the mapping definition - try commenting it out and it should just work - stackoverflow.com/questions/29281381/… - V H
I solved with: id column: "id", type:"long", sqlType: "int", generator: 'increment' ... editing type of generator! increment for assignated! - JuanManuel245

2 Answers

1
votes

replace generator attributes assigned by

identity

which is for mySQL

static mapping = {
     id column: "id", type: "long", sqlType: "int", generator: 'identity'
     datasource 'dialer'
     version false
     }

more infomation about hibernate generator(ctrl + F "IDENTITY")

0
votes

The solution is remplace assignated for incremental

id column: "id", type:"long", sqlType: "int", generator: 'increment'