how set start value for auto increment in grails

一曲冷凌霜 提交于 2019-12-13 02:06:03

问题


I am using my custom auto increment key in my domain class using

 static mapping = { id generator: 'increment', name: 'personId' }

Is it possible to start the auto increment from a particular value , say start from 100 ?


回答1:


You can set the initial value of the autoincrement by using the org.hibernate.id.enhanced.SequenceStyleGenerator generator. This generator takes the parameter initial_value, which will be the the value of your first id. (And after that, it will increment by 1, just like you are used to.)

static mapping = {
    id(generator: 'org.hibernate.id.enhanced.SequenceStyleGenerator', 
        params: [sequence_name: 'start_seq', initial_value: 100])
}


来源:https://stackoverflow.com/questions/29281381/how-set-start-value-for-auto-increment-in-grails

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