Steve Ebersole and other participants,
Could you explain the reason for id with a large gap (default is 50)? I am using Hibernate 4.2.15 and found the following code in org.hibernate.id.enhanced.OptimizerFactory cass.
if ( lo > maxLo ) { lastSourceValue = callback.getNextValue(); lo = lastSourceValue.eq( 0 ) ? 1 : 0; hi = lastSourceValue.copy().multiplyBy( maxLo+1 ); } value = hi.copy().add( lo++ );
Whenever it gets inside an if statement, the value of hi becomes much larger. Thus, during testing with frequent server restarts, my identifier generates the following sequence identifiers:
1, 2, 3, 4, 19, 250, 251, 252, 400, 550, 750, 751, 752, 850, 1100, 1150.
I know that you have already said that this does not contradict the specification, but I believe that this will be a very unexpected situation for most developers.
Any input would be very helpful.
Jihwan
UPDATE: ne1410s: Thanks for editing.
cfrick: OK. I will do it. This was my first post here and was not sure how to use it.
Now I better understand why maxLo was used for two purposes: since hibernate calls the DB sequence once, keep increasing the identifier at the Java level and save it in the database, the value of the Java level identifier should take into account how much was changed without calling the database sequence when it calls sequence next time.
For example, the sequence identifier was 1 at the point, and sleep mode was 5, 6, 7, 8, 9 (with allocSize = 5). The next time we get the next serial number, DB returns 2, but hibernate should use 10, 11, 12 ... Therefore, "hi = lastSourceValue.copy (). MultiplyBy (maxLo + 1)" is used to get the next identifier 10 out of 2 returned from the database sequence. It seems that this was only during a frequent server restart, and that was my problem with a big gap.
So, when we use the SEQUENCE ID, the inserted identifier in the table will not correspond to the SEQUENCE number in the database.