【问题标题】:How to use a custom id column in GORM如何在 GORM 中使用自定义 id 列
【发布时间】:2010-12-07 19:01:06
【问题描述】:

我有一个域对象,它有一个属性,我想被 GORM 用作 id,原因是我将保存这个对象的列表,我希望现有的行被 更新 如果 id 已经存在于数据库中

假设我想要作为 PK 的属性称为 listId

我见过几种方法,哪种方法最好?

1:

id generator: 'identity', column: 'listId'

2:

  static mapping = {
    id generator:'assigned'
  }
  def getKey = {
    return listId;
  }

还是完全不同的东西?

【问题讨论】:

    标签: grails grails-orm


    【解决方案1】:
      static mapping = {
        id generator: 'assigned', name: "listId", type: 'string'
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-23
      • 2019-05-02
      • 2021-11-03
      • 1970-01-01
      相关资源
      最近更新 更多