Hello
I have found one problem in TableHiLoGenerator I compare the source code of hibernate with the nhibernate and the error is only in nhibernate.
When I use the table hilo id generator, the id jumps 1 number each time the lo passes the maxLo because the nhibernate code doesn't have one verification that the hibernate code does.
this is the code in nhibernate TableHiLoGenerator function:
Code:
if (lo > maxLo)
{
long hival = ((long) base.Generate(session, obj));
lo = 1;
hi = hival * (maxLo + 1);
log.Debug("new hi value: " + hival);
}
return IdentifierGeneratorFactory.CreateNumber(hi + lo++, returnClass);
And this is the code in hibernate:
Code:
if (lo>maxLo) {
long hival = ( (Number) super.generate(session, obj) ).longValue();
lo = (hival == 0) ? 1 : 0;
hi = hival * (maxLo+1);
log.debug("new hi value: " + hival);
}
As you can see in hibernate the lo initialization check if it has value 0 to initialize in value 1 or different than 0 to initialize in 0. With this verification the "one number jump" does not happend.
other solution could be not to increment in 1 the hi value.
example:
Code:
if (lo > maxLo)
{
long hival = ((long) base.Generate(session, obj));
lo = 1;
hi = hival * maxLo;
log.Debug("new hi value: " + hival);
}
return IdentifierGeneratorFactory.CreateNumber(hi + lo++, returnClass);
I tested this solution and it work fine for me.
I would like to know if I should put this in jira and if I do, like bug or like what?