问题
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