@GeneratedValue(strategy = GenerationType.SEQUENCE)和startVaule [英] @GeneratedValue(strategy = GenerationType.SEQUENCE) and startVaule
本文介绍了@GeneratedValue(strategy = GenerationType.SEQUENCE)和startVaule的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以设置第一个值,因此它会得到id 10000 ... n?
解决方案
SequenceStyleGenerator 应该如此:
@GeneratedValue(generator = SEQUENCE_GENERATOR)
@GenericGenerator(name = SEQUENCE_GENERATOR,
strategy =org.hibernate.id.enhanced .SequenceStyleGenerator,参数= {
@Parameter(name =sequence_name,value =my_sequence),
@Parameter(name =initial_value,value =1001),
@Parameter(name =increment_size,value =1),
@Parameter(name =value_column,value =my_squence_id)})
when using the @GeneratedValue Annotation in Hibernate, and adding a new Entity to DB it has the id 1 ... n . Is is it possible to set the first value, so it would get the id e.g. 10000 ... n ?
解决方案
SequenceStyleGenerator should to the trick:
@GeneratedValue(generator = SEQUENCE_GENERATOR)
@GenericGenerator(name = SEQUENCE_GENERATOR,
strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator", parameters = {
@Parameter(name = "sequence_name", value = "my_sequence"),
@Parameter(name = "initial_value", value = "1001"),
@Parameter(name = "increment_size", value = "1"),
@Parameter(name = "value_column", value = "my_squence_id") })
这篇关于@GeneratedValue(strategy = GenerationType.SEQUENCE)和startVaule的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文