【问题标题】:Grails id mapping autoincrement - MySQLGrails id 映射自动增量 - MySQL
【发布时间】:2019-03-28 14:32:24
【问题描述】:

我有一个 ID 属性为自动增量的 MySQL 表,我需要它,当从 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 ()

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

【问题讨论】:

  • grails id 在没有映射定义的情况下自动递增 - 尝试将其注释掉,它应该可以正常工作 - stackoverflow.com/questions/29281381/…
  • 我解决了:id column: "id", type:"long", sqlType: "int", generator: 'increment' ...编辑生成器的类型!分配的增量!

标签: mysql grails hibernate-mapping auto-increment grails-domain-class


【解决方案1】:

替换由

分配的生成器属性

身份

用于 mySQL

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

more infomation关于休眠生成器(ctrl + F "IDENTITY")

【讨论】:

    【解决方案2】:

    解决方案被替换为增量分配

    id 列:“id”,类型:“long”,sqlType:“int”,生成器:'increment'

    【讨论】:

      猜你喜欢
      • 2011-02-02
      • 1970-01-01
      • 1970-01-01
      • 2021-03-03
      • 1970-01-01
      • 1970-01-01
      • 2021-05-01
      • 2011-10-22
      • 2016-09-27
      相关资源
      最近更新 更多