Search code examples
javadatabasehibernate

@GeneratedValue(strategy = GenerationType.SEQUENCE) and startVaule


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 ?


Solution

  • 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") })