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:
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
Upon first firing of generate(), it sets the value to be 49 behind the actual sequence. A possible fix could be
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.
Apache Tomcat 7.0.65