I have legacy Oracle db with a sequence named PRODUCT_ID_SEQ.
Here is the mapping of Product class for which I need generate correct ids:<
allocationSize and incrementBy are completely different things.
Hibernate is of course using your sequence created in DB but depending on allocationSize you might find gap in generated value.
For example- Let assume current sequence value is 5, increment by 1 in db, and allocationSize default 50.
Now you want to save a collection of 3 element through hibernate, then Hibernate will assign generated id 250, 251, 252
This is for optimization purpose. Hibernate doesn't have to go back to db and fetch next incremented value.
If you don't want this just setting allocationSize = 1 as already answered will do the purpose