如何在grails中设置自动增量的起始值 [英] how set start value for auto increment in grails
本文介绍了如何在grails中设置自动增量的起始值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用域类中的自定义自动增量键
I am using my custom auto increment key in my domain class using
static mapping = { id generator: 'increment', name: 'personId' }
是否可以从特定值开始自动递增,例如从100开始?
Is it possible to start the auto increment from a particular value , say start from 100 ?
推荐答案
您可以使用org.hibernate.id.enhanced.SequenceStyleGenerator
生成器设置自动增量的初始值.该生成器采用参数initial_value
,它将是第一个id
的值. (然后,它将像以前一样增加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])
}
这篇关于如何在grails中设置自动增量的起始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文