1

Originally Hibernate inserted new values with ID starting from 50. But after redeployment the new IDs are 50050, 50051 etc.

Why so? How do I configure it to increment by 1 always?

DB is Oracle.

Sequence's SQL:

create sequence my_seq increment by 1 cache 1000;

Column setup:

@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqGeneratorMySeq")
@SequenceGenerator(name = "seqGeneratorMySeq", sequenceName = "MY_SEQ")
private Long id;
Mary
  • 45
  • 8
  • you should check the `curval` of the sequence in the database. I think hibernate here has nothing to do. If you are redeploying, are you recreating the sequence from scratch ? – Roberto Hernandez Oct 18 '21 at 13:41
  • If you cache by 1000 and restart you may not get the next sequence as +1. There is no guarantee that the next sequence will be +1 of the prior sequence. You could maybe set the cache to 1, but that is not efficient. – OldProgrammer Oct 18 '21 at 14:16
  • Check the setting of [`hibernate.id.new_generator_mappings`](https://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-mapping-identifier) if it is `true`. See also [here](https://stackoverflow.com/a/67939356/4808122) comment to the `cache` size – Marmite Bomber Oct 18 '21 at 14:17
  • @MarmiteBomber but I think I had problems when the first value was true. I guess Hibernate was trying to find its own sequence and not mine in the db. – Mary Oct 18 '21 at 14:47

1 Answers1

0

Answer found here In short: set up sequence params (like increment, cache size, etc) in the Entity class, not only in DB

Mary
  • 45
  • 8