How to change primary key column in grails?

我们两清 提交于 2019-11-27 06:45:17

问题


I have a domain class having an Integer variable 'code'. my requirement is to make 'code', primary key column for that domain and also auto increment and to remove the default 'id' column from the table created for that doamin.thnks


回答1:


use this :

static mapping = {
id name: 'code'
}

more informations here : http://grails.org/doc/2.0.x/ref/Database%20Mapping/id.html




回答2:


Domain classes in Grails by default dictate the way they are mapped to the database using sensible defaults. You can customize these with the ORM Mapping DSL.

Customizes the way the identifier for a domain class is generated with id. See the Grails documentation for id.

static mapping = {
    id column: 'code', type: 'integer'
}


来源:https://stackoverflow.com/questions/10120708/how-to-change-primary-key-column-in-grails

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!