【问题标题】:Assigned domain class id wierdness with Grails使用 Grails 分配域类 id
【发布时间】:2011-10-28 21:26:49
【问题描述】:

我想在 grails 1.3.7 上手动设置 id

这会编译,但 id 始终为 0

//in bootstrap
def it1 = new ItemType(id:4,name:'feature')
it1.save()
//domanin class
class ItemType {
    String name
    int id

    static constraints = {
        id(unique:true,blank:false)
        name(blank:false)
    }

    static mapping = {
        id column: 'ItemTypeId', generator:'assigned'
        name column: 'Name'
        version false
    }
}

这会编译和 id 4(根据需要)

//in bootstrap
def it1 = new ItemType(name:'feature')
it1.id=4
it1.save()
//domanin class
class ItemType {
    String name
    //int id

    static constraints = {
        id(unique:true,blank:false)
        name(blank:false)
    }

    static mapping = {
        id column: 'ItemTypeId', generator:'assigned'
        name column: 'Name'
        version false
    }
}

所以我的问题是有没有办法让 id 作为道具但被分配?

【问题讨论】:

    标签: grails grails-orm


    【解决方案1】:

    前几天遇到同样的问题:my own id in GORM

    这似乎是一个功能:-)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-26
      • 1970-01-01
      • 1970-01-01
      • 2011-11-29
      • 2015-02-03
      相关资源
      最近更新 更多