Grails id映射自动增量 - MySQL

问题描述 投票:0回答:2

我有一个MySQL表,ID属性为自动增量,我需要这样做,当从Grails进行插入时,id的值会自动完成增加。

我的grails类有以下映射:

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

但是想要进行插入会给我以下错误:

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

他们会帮我一把吗?谢谢!

mysql grails hibernate-mapping auto-increment grails-domain-class
2个回答
0
投票

替换指定的生成器属性

身分

这是为mySQL

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

关于hibernate生成器的more infomation(ctrl + F“IDENTITY”)


0
投票

解决方案是为增量分配remplace

id列:“id”,类型:“long”,sqlType:“int”,generator:'increment'

© www.soinside.com 2019 - 2024. All rights reserved.