0

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!

  • grails id auto increments without the mapping definition - try commenting it out and it should just work - https://stackoverflow.com/questions/29281381/how-set-start-value-for-auto-increment-in-grails – V H Mar 28 '19 at 14:51
  • I solved with: id column: "id", type:"long", sqlType: "int", generator: 'increment' ... editing type of generator! increment for assignated! – JuanManuel245 Mar 28 '19 at 15:02

2 Answers2

1

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")

Lonyui
  • 93
  • 9
0

The solution is remplace assignated for incremental

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