开发者

How to use a custom id column in GORM

开发者 https://www.devze.com 2023-01-29 02:56 出处:网络
I have a domain object that has a property that i want to be used as the id by GORM, the reason being is that ill be saving lists of this object and i want existing rows to be updated if the id alread

I have a domain object that has a property that i want to be used as the id by GORM, the reason being is that ill be saving lists of this object and i want existing rows to be updated if the id already exists in the database

Lets assume that my property i want as the PK is called listId

Ive seen several approaches to this, which is best?

1:

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

2:

  static mapping = {
    id generator开发者_开发知识库:'assigned'
  }
  def getKey = {
    return listId;
  }

or something entirely different?


  static mapping = {
    id generator: 'assigned', name: "listId", type: 'string'
  }
0

精彩评论

暂无评论...
验证码 换一张
取 消