| When attempting to persist an entity through EntityManager.persist, the sequence generator returns an old value. This causes a constraint violation and makes this version unusable for us. The field is defined as follows:
@Id
@SequenceGenerator(name = "our_entity_gen", sequenceName = "our_entity_seq")
@GeneratedValue(generator = "our_entity_gen")
private Long id;
Within the database the value of the sequence is around 130, but the JPA attempts to persist it with an id that around 80 (both numbers increase on each attempt). As far as I've been able to trace the problem, it comes from org.hibernate.id.enhanced.PooledOptimizer lines 88 and 89
generationState.hiValue = generationState.value;
generationState.value = generationState.hiValue.copy().subtract( incrementSize - 1 );
Upon first firing of generate(), it sets the value to be 49 behind the actual sequence. A possible fix could be
generationState.hiValue = generationState.value.copy().add( incrementSize - 1 );
However I haven't looked if the rest of the implementation keeps the value properly in sync with the database. P.S. we are still using a custom build of 4.3.10 with 3 fixes to bypass the problems preventing us from using the official versions. Two other problems that impacted us have been fixed so far. I hope 5.0.9 will finally allow us to finally return to the official builds. |