I have configured hibernate to use oracle sequence. Sequence is created with cache=20, increment=1.
All works fine, hibernate persisting entities. The id value is st
I take it that your question is that the values of the ID column in the database are not a natural sequence, but why you are seeing gaps:
A bit of background:
select HIBERNATE_SEQUENCE.nextval from DUAL
the value of the sequence is increased.For example, consider the following scenario:
You've got two entities Entity1 and Entity2 using HIBERNATE_SEQUENCE as the ID generator:
select HIBERNATE_SEQUENCE.nextval from DUAL
(returns 104)So at the end of it you'll have:
which explains the gaps.
EDIT:
Even if the @SequenceGenerator were setup to use the SequenceGenerator
rather than the SequenceHiLoGenerator
(as pointed out by JB Nizet, which I think is a better explanation for the gaps), gaps in IDs generated by sequences are a common occurrence.