Description
Tomas Gerhardsen created an issue — 10th June 2016, 5:48:01:
The hilo optimizer is not calculating the correct id when called from two different processes.
You will get Primary key Violations if you use the enhanced tablegenerator with hilo and two different processes sharing the same db.
Once the optimizer reaches the upper limit of a bucket it should get a new one from db and use it to calculate the new bucket. This does not happen.
The code:
else if (_upperLimit <= _value) { _lastSourceValue = callback.GetNextValue(); _upperLimit = (_lastSourceValue * IncrementSize) + 1; } return Make(_value++); //<--- New _upperLimit not used. We will get duplicate identities If another process called thisShould be something like:
else if (_upperLimit <= _value) { _lastSourceValue = callback.GetNextValue(); _upperLimit = (_lastSourceValue * IncrementSize) + 1; _value = _upperLimit - IncrementSize; } return Make(_value++);
Oskar Berggren added a comment — 10th June 2016, 8:46:48:
Strange... Could you dig up a reference to the corresponding code in Hibernate please?
Tomas Gerhardsen added a comment — 10th June 2016, 10:58:56:
The bug is found in Hibernate also: https://hibernate.atlassian.net/browse/HHH-3628
It is not fixed yet in the main branch: https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/id/enhanced/HiLoOptimizer.java#L80