This post is old, but for others that may have the same problem.
As Steve Ebersole pointed out, you should use the pooled-lo optimizer in your case. Check also your version of sleep mode, it should be> = 4.3.11, because in previous versions in issue .
To give some explanation, with the pooled-lo optimizer, the value stored in the database is the low value of the next available interval.
So, if the identifier of the last object is stored in [1; 10], the next available interval [11,20], and the value stored in the database will be 11, as expected.
Thus, if you have another program that does not use hibernate and does not even know the size of the increment defined in the sleep mode configuration, it will still be able to insert objects without breaking the sequence.
All you have to do is atomize the value of the sequence and increase it, and then use the value obtained (before "incrementation") as the new identifier of the object that it wants to insert. In our example, to insert one row, it will update the sequence value to 12 and add a new object with identifier 11. Thus, when hibernate reaches the last id of its current interval in memory (10), it will query the database and save the value 22, so that save a new id interval for it [12; 21].
source share