@GeneratedValue (strategy = GenerationType.SEQUENCE) and startVaule

when using @GeneratedValue Annotation in Hibernate and adding a new Entity to DB, it has the identifier 1 ... n. Is it possible to set the first value so that it gets an identifier, for example. 10000 ... n?

+3
source share
1 answer

SequenceStyleGenerator should do 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") })
+3
source

Source: https://habr.com/ru/post/1729230/


All Articles